[英]Spring: - How can we get Bean if context are loaded from web.xml?
I am learning spring
which is being used in my project.I found the contextConfigLocation
entry in my web.xml 我正在学习在项目中使用的spring
。我在web.xml中找到了contextConfigLocation
条目
/WEB-INF/context/*-context.xml
classpath:/context/database-context.xml
classpath:/context/database-service-context.xml
classpath:/context/business-process-management-service-context.xml
and listener 和听众
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
In a core project which I read like below 在一个我读如下的核心项目中
Resource r=new ClassPathResource("applicationContext.xml");
BeanFactory factory=new XmlBeanFactory(r);
Employee s=(Employee)factory.getBean("e");
But could not figure out how things are working and where getBean()
function is called ? 但是无法弄清楚事情是如何工作的以及在何处调用getBean()
函数吗?
You can retrieve the WebContext with this method: 您可以使用以下方法检索WebContext:
http://docs.spring.io/spring/docs/3.0.x/javadoc-api/org/springframework/web/context/support/WebApplicationContextUtils.html#getWebApplicationContext%28javax.servlet.ServletContext%29 http://docs.spring.io/spring/docs/3.0.x/javadoc-api/org/springframework/web/context/support/WebApplicationContextUtils.html#getWebApplicationContext%28javax.servlet.ServletContext%29
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.