[英]applicationContext.xml is being copied to /WEB-INF/classes from src/main/resources
however tomcat is throwing the error : 但是tomcat抛出错误:
IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml];
Which suggests that tomcat expects the applicationContext.xml to be one directory above where it is copied to. 这表明tomcat希望applicationContext.xml在其复制到的目录上方。 It is being copied to the /WEB-INF/ classes directory, not just the plain old /WEB-INF 它被复制到/ WEB-INF / classes目录,而不仅仅是普通的/ WEB-INF
I am using maven. 我正在使用Maven。
如果已将其放在src / main / resources下,则应将资源称为classpath:/applicationContext.xml
In your web.xml
you can state where your applicationContext.xml
is located. 在web.xml
,可以声明applicationContext.xml
的位置。 If it is in /WEB-INF/classes
then you must state /WEB-INF/classes/applicationContext.xml
(and not just /WEB-INF/applicationContext.xml
). 如果它在/WEB-INF/classes
则必须声明/WEB-INF/classes/applicationContext.xml
(而不仅仅是/WEB-INF/applicationContext.xml
)。
Try this: 尝试这个:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/classes/applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
To include more than one context files you can use the import
function. 要包含多个上下文文件,可以使用import
功能。 To do so, write into your applicationContext.xml
one line per file like this: 为此,将每个文件一行写入到applicationContext.xml
如下所示:
<import resource="myOtherSpringContext.xml"/>
Use the following syntax in your web.xml ( http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/web/context/ContextLoader.html ): 在web.xml( http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/web/context/ContextLoader.html )中使用以下语法:
<!-- list of the configuration files to load -->
<context-param>
<!-- Spring -->
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml</param-value>
</context-param>
It will load it from the classes/* directory. 它将从classes / *目录加载它。 BTW, if you want to copy the applicationContext.xml directly in your WEB-INF directory, move it in /src/main/webapp 顺便说一句,如果您想直接在WEB-INF目录中复制applicationContext.xml,请将其移至/ src / main / webapp
BTW, here is the way recommanded by the spring documentation: http://static.springsource.org/spring/docs/3.0.x/reference/beans.html#context-create 顺便说一句,这是春季文档推荐的方式: http : //static.springsource.org/spring/docs/3.0.x/reference/beans.html#context-create
HIH HIH
This is standard Maven behaviour, and is what a lot of people use with no objection. 这是Maven的标准行为,这是很多人毫无异议地使用的行为。 Why do you prefer it in WEB-INF? 为什么在WEB-INF中更喜欢它?
Anyway, if you want it there, you can just put it in src/main/webapp/WEB-INF
. 无论如何,如果您需要它,可以将其放在src/main/webapp/WEB-INF
。
the standard way is to create new source dir src/main/webapp
. 标准方法是创建新的源目录src/main/webapp
。 All files from this dir will be places in the same folder as WEB-INF in resulting war. 该目录中的所有文件将与WEB-INF放在同一文件夹中,从而导致战争。 So, inside this new source dir you can create WEB-INF
and place you applicationcontext.xml
in it. 因此,在这个新的源目录中,您可以创建WEB-INF
并将applicationcontext.xml
放入其中。
so you structure would look much like 所以你的结构看起来很像
+src
+---main
+---+---java
+---+---webapp
+---+------WEB-INF
check maven-war-plugin documentation 查看Maven-war-plugin文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.