Spring - 别名与名称的使用

标签 spring

我对别名的使用感到困惑。我确实了解别名是什么以及它是如何使用的,但我看不出它与在 bean 定义中使用名称有何不同。

<bean id="xyx" name="abc,def" .. />

<alias name="xyx" alias="pqr"/>

当我可以使用 abc 或 def 时为什么要使用别名?

最佳答案

在我看来,bean 别名在您无法操作 bean 名称的大型系统中很有帮助。您可以选择为您的系统部分创建自己的名称(别名)...

来自 Spring 文档 (3.0.x) http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/htmlsingle/

...it is sometimes desirable to give a single bean multiple names, otherwise known as bean aliasing...

因此创建多个名称或/和别名是一回事。

关于Spring - 别名与名称的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15211590/

相关文章:

xml - tomcat7-maven-plugin log4j : no appender could be found for logger (org. apache.catalina.startup.Catalina)

java - 使用 Spring Boot 隐式提供 index.html

java - Spring Security 4 防止并发登录不起作用

java - 在 Spring 中使用 jdbcTemplate 的简单示例时出现空指针异常

java - HttpServletRequestWrapper,setReadListener/isFinished/isReady 的示例实现?

java - Spring Security hasPermission for Collection<Object>

java - 为什么服务层和 dao 层总是有单一的实现接口(interface)?

java - 确定此 REST 应用程序背后的工具?

java - spring jndi NamingException : Name [spring. liveBeansView.mbeanDomain] 未绑定(bind)在此上下文中

spring - 如何覆盖 Spring Boot 依赖项的默认版本?