0

If I have a configuration file (yml or properties) and I have a blank entry like the one below:

some.entry =

When I load that entry as a @Resource of a given bean, like this:

@Resource(name = "someEntry")
Map<String, List<String>> someMap;

Will the someMap end up as null or an empty Map?

And would the behavior be different if instead of @Resource a similar approach with @Value is used?

Filipe Freire
  • 823
  • 7
  • 21
  • `@Resource` seems to require an existing bean which can ge injected. If no such bean is defined it throws a `org.springframework.beans.factory.NoSuchBeanDefinitionException`. Info from [this website](http://www.baeldung.com/spring-annotations-resource-inject-autowire). Sadly they don't tell what happens if you use a file whith only the identifier. I would assume that it becomes `null` as you don't define anything but the name – XtremeBaumer Mar 14 '18 at 14:19
  • it's been answered in this post: [https://stackoverflow.com/questions/4093504/resource-vs-autowired](https://stackoverflow.com/questions/4093504/resource-vs-autowired) – David Han Mar 14 '18 at 14:22
  • @davidhan I can't seem to find where they answer what the value of the variable becomes after loading for this scenario, independently of Resource,Autowired, etc. Where did you see that info? – Filipe Freire Mar 14 '18 at 14:26
  • @XtremeBaumer I assume that too, but I wanted to be sure if it either becomes `null` or it becomes an empty Map. – Filipe Freire Mar 14 '18 at 14:27
  • You could simply test it – XtremeBaumer Mar 14 '18 at 14:28

1 Answers1

1

Both @Resource and @Value will convert some.entry = to null.

Pedro Tavares
  • 1,119
  • 8
  • 19