如何在Spring bean中使用简单的类名? [英] How can I use the simple class name in Spring beans?

查看:132
本文介绍了如何在Spring bean中使用简单的类名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用

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

而不是

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

是否有可能导入一个包?

Is there a possibility to import a package?

同一个包中有很多类,我想让XML文件更具可读性。

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

推荐答案

您似乎不能使用简单的类名而不是完全限定的类名,因为这个Stack Overflow文章讨论(和qv Spring文档本身),除非你的bean oneId 仅作为子bean的父级使用。

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.

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

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.

这篇关于如何在Spring bean中使用简单的类名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆