简体   繁体   English

如何在Spring bean中使用简单的类名?

[英]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. 同一个包中有很多类,我想让XML文件更具可读性。

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. 看起来你不能使用简单的类名而不是完全限定的类名,因为这篇Stack Overflow文章讨论了(并且修改了Spring文档本身),除非你的bean oneId仅用作子bean的父类。

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. 但是,如果使用注释而不是XML描述符文件,则可以使用简单类名OneClass并允许import语句处理包名限定符的混乱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Spring Context 中创建两个相同类的 bean? - How can I create two beans of same class in a Spring Context? 如何将 spring beans 注入 jersey 的资源类? - How can I inject spring beans into jersey's resources class? 在春季,如何定义两个具有相同名称和不同类的Bean - In Spring, How to Define Two Beans, with Same Name and Different Class 如何使用Spring XML配置来设置包含特定类型的所有bean的列表的bean属性? - How can I use Spring XML configuration to set a bean property with list of all beans of a certain type? 我可以使用注入的bean作为另一个类的方法的参数吗? - Can I use injected beans as arguments for another class' method? 如何自动使用班级名称? - How can I automatically use the name of the class? 如何使用Spring HibernateOperations对隐式事务进行简单操作? - How can I use Spring HibernateOperations for simple operations with a implicit transaction? 在 liquibase CustomTaskChange 类中使用其他 spring bean - Use other spring beans in liquibase CustomTaskChange class 如果我在配置 class 上使用 @ActiveProfiles 注释而不是在定义我的 bean 的 class 上使用它,Spring 会发生什么? - What happens in Spring if I use the @ActiveProfiles annotation on a configuration class instead use it on the class that defines my beans? 如何确保Spring Bean的加载顺序? - How can I ensure the loading order of Spring Beans?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM