简体   繁体   中英

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.

It appears that you cannot use the simple class name instead of the fully qualified class name, as this Stack Overflow article discusses (and qv 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM