简体   繁体   English

applicationContext.xml从src / main / resources复制到/ WEB-INF / classes

[英]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.

相关问题 Maven将applicationContext.xml从src / main / resources复制到target / myproject / WEB-INF - Maven copying applicationContext.xml from src/main/resources to target/myproject/WEB-INF 创建URL [/WEB-INF/classes/applicationContext.xml]中定义的名称为&#39;persistenceUnitManager&#39;的bean时出错:无法解析 - Error creating bean with name 'persistenceUnitManager' defined in URL [/WEB-INF/classes/applicationContext.xml]: Cannot resolve 无法打开ServletContext资源[/WEB-INF/applicationContext.xml] - Could not open ServletContext resource [/WEB-INF/applicationContext.xml] 来自ServletContext资源[/WEB-INF/applicationContext.xml]的意外异常解析XML文档; - Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; 严重:上下文初始化失败/WEB-INF/applicationContext.xml无效 - SEVERE: Context initialization failed /WEB-INF/applicationContext.xml is invalid 我有WEB-INF / applicationContext.xml但应用程序找不到它 - I have WEB-INF/applicationContext.xml but application cannot find it [/WEB-INF/applicationContext.xml]:java.lang.VerifyError:类org.hibernate.type.WrappedMaterialized - [/WEB-INF/applicationContext.xml]: java.lang.VerifyError: class org.hibernate.type.WrappedMaterialized 创建在servlet上下文资源[WEB-INF / applicationContext.xml]中定义的名称为“ datasource”的bean时出错 - Error creating bean with name “datasource” defined in servlet context resource [WEB-INF/applicationContext.xml] 个性化的ApplicationContextInitializer可能是错误的原因无法打开ServletContext资源[/WEB-INF/applicationContext.xml]? - Personalized ApplicationContextInitializer can be the cause of Error Could not open ServletContext resource [/WEB-INF/applicationContext.xml]? Spring安全配置错误/WEB-INF/applicationContext.xml,并且没有名为springSecurityFilterChain的bean - Spring security configuration error /WEB-INF/applicationContext.xml and there's no bean called springSecurityFilterChain
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM