在Spring应用程序中处理* -context.xml和applicationContext.xml文件
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了在Spring应用程序中处理* -context.xml和applicationContext.xml文件,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2094字,纯文字阅读大概需要3分钟。
内容图文
![在Spring应用程序中处理* -context.xml和applicationContext.xml文件](/upload/InfoBanner/zyjiaocheng/653/c5ce4ebdeeee40bb8fb1711f9329d300.jpg)
我正在使用Spring Web MVC作为事务休眠的前端(所有注释驱动).我将web.xml设置如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>wdman</display-name>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>wdman</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>wdman</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<!-- Disables Servlet Container welcome file handling.
Needed for compatibility with Servlet 3.0 and Tomcat 7.0 -->
<welcome-file-list>
<welcome-file></welcome-file>
</welcome-file-list>
</web-app>
我不明白< tx:annotation-driven />从根上下文(在本例中为一个已定义的applicationContext.xml)继承到* -servlet.xml上下文.它似乎不起作用.我在这两个文件中都进行了组件扫描,以使应用程序正常工作.这可以吗?组件不重复吗?
您能帮我指出一些简洁的文档,描述这些上下文如何合并吗?
解决方法:
I don’t understand how are options like
<tx:annotation-driven/>
inherited from root context (in this case the one definedapplicationContext.xml
) to*-servlet.xml
context
他们不是.这些设置是上下文本地的.
I have
component-scan
in both of these files in order to get application working. Is that ok? Aren’t the components duplicated?
如果在每个上下文中都有相同的component-scan配置,则可以,这些组件将被复制.由您决定指定扫描仅实例化每个上下文所需的组件.
但是,applicationContext.xml中定义的bean对子上下文是可见的,因此您应该能够在父上下文中保持组件扫描,并将其保留在子上下文之外.根据经验,只有特定于MVC的东西才需要在servlet上下文中声明,并且那些bean可以引用父对象中定义的bean.
内容总结
以上是互联网集市为您收集整理的在Spring应用程序中处理* -context.xml和applicationContext.xml文件全部内容,希望文章能够帮你解决在Spring应用程序中处理* -context.xml和applicationContext.xml文件所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。