将spring-servlet.xml保留在Web应用程序中后,未加载applicationContext.xml [英] applicationContext.xml is not getting loaded when I have kept the spring-servlet.xml in Web application
问题描述
我正在使用Eclipse开发Web应用程序. Spring MVC Web应用程序将得到完善. 我已经创建了servlet xml并将其映射到web.xml中. 一切正常,直到这里& Servlet加载HTML页面 但是现在我想添加一个JPA层. 因此,我在WEB-INF中创建了applicationContext.xml,并将所有与JPA相关的spring配置放入该文件中. 但是,当我启动Web应用程序时,未加载与JPA相关的内容. 我相信的是,applicationContext.xml本身未加载. 我在这里缺少任何想法或其他配置吗?
I am Working on a web application in eclipse. A spring MVC web applicatication to be precised. I have created servlet xml and mapped it in web.xml. Everything is working fine till here & Servlet loads the HTML page But now I want to add a JPA layer. So I have created applicationContext.xml in WEB-INF and put all JPA related spring configurations in that file. But when I start my web application, JPA related stuff is not getting loaded. What I believe is, applicationContext.xml itself is not getting loaded. Any Idea or any other configuration I am missing here?
推荐答案
除非您在
web.xml
或其他类似的配置文件中配置springContextLoaderListener
,否则默认情况下不会加载applicationContext.xml
文件.
The
applicationContext.xml
file is not loaded by default unless you configure springContextLoaderListener
in theweb.xml
or other similar configuration file.
我假设applicationContext.xml
位于WEB-INF
文件夹中.
I am assuming that the applicationContext.xml
is present inside WEB-INF
folder.
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
如果您有多个配置文件,则可以将它们指定为,
分隔的值,例如
If you have multiple configuration files, you can specify them as ,
separated values like
<param-value>
classpath:applicationContext.xml,
classpath:securityContext.xml
</param-value>
<param-value>
classpath:applicationContext.xml,
classpath:securityContext.xml
</param-value>
这篇关于将spring-servlet.xml保留在Web应用程序中后,未加载applicationContext.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!