Spring bean with no id or name

I'm reviewing some Spring code, and I see a few bean defs that do not have an id or a name. The person who did it is not around to ask. The application is working fine. I am not familiar what this necessarily means. Anybody know if this means anything in particular?

Answers


Some beans are not required to be accessed by other beans in the context file or programmatically. So as mentioned by JacobM, they don't require an id or name as they're not referenced.

Such an example would be a PropertyPlaceholderConfigurer, which reads a property file, then allows for runtime property replacement in the context definition.

The example definition would be

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="location" value="myapp.properties" />
</bean>

The JavaDoc provides further documentation on this object, but further on in the file you can reference properties from your file by just using the standard template replace placeholder ${...}.


Need Your Help

Avoid validation on int field MVC3

asp.net-mvc-3 validation data-annotations

I have the following ViewModel (just showing few properties for easy reading)

How do I call a method in the default instance of a VB.NET Form instead of instantiating another?

vb.net class forms

When an instantiated class calls a method in the parent form class, VB.NET starts a new instance of the form class instead of calling the method on to the active one!