ROMANIA_engineer
ROMANIA_engineer

Reputation: 56684

How can I use the simple class name in Spring beans?

How can I use

<bean id="oneId" class="OneClass">
    <property name="prop" ref="anotherBean">
</bean>

instead of

<bean id="oneId" class="com.bla.bla.bla.OneClass">
    <property name="prop" ref="anotherBean">
</bean>

?

Is there a possibility to import a package?

There are a lot of classes from the same package and I'd like to make the XML file more readable.

Upvotes: 1

Views: 2258

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521794

It appears that you cannot use the simple class name instead of the fully qualified class name, as this Stack Overflow article discusses (and q.v. the Spring documentation itself), unless your bean oneId serves only as a parent for child beans.

However, if you use annotations instead of the XML descriptor files, you can use the simple class name OneClass and allow the import statement to handle the messiness of the package name qualifier.

Upvotes: 3

Related Questions