我已经在一个项目上独自工作了很长时间,现在另一个开发人员加入了,所以我想通过 SVN 在他的机器上设置该项目。我们都使用非常相似的设置:
- OS X 雪豹
- 最新 Eclipse WTP
- m2eclipse Maven 插件
- 颠覆性的 SVN 插件
- Tomcat 6.0.24
使用的Spring版本是2.5.6。
我使用 Eclipse 的“Project from SVN”工具在他的计算机上设置了该项目,本质上是创建该项目的 1:1 副本。据我所知,Maven 处理了所有依赖关系,没有出现任何问题,项目编译也没有出现任何问题。项目结构遵循 Web 应用程序的 Maven 标准,资源(如 applicationContext.xml)位于 src/main/resources 中,项目代码位于 src/main/java 中,所有与 Web 应用程序相关的文件位于 src/main/webapp 和 src 中分别为/main/webapp/WEB-INF。
web.xml 配置为加载上下文,如下所示:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
使用 Eclipse 的“服务器”工具,我尝试直接从 Eclipse 启动应用程序,但在尝试加载 applicationContext.xml 时,它立即失败并出现 FileNotFoundException。
由于从 SVN checkout 的代码未受影响,我猜问题与 Maven 插件的某些参数有关。或者我忘记了完成设置的一些重要步骤。有没有人遇到过类似的问题或知道我应该从哪里开始寻找?
非常感谢您的帮助!
最佳答案
The project structure is following the Maven standard for webapps with resources (like the applicationContext.xml) in src/main/resources, the project's code in src/main/java and all web-app related files in src/main/webapp and src/main/webapp/WEB-INF respectively.
这是正确的并且非常好(因为您希望 applicationContext.xml
位于测试类路径上)。
It is not copied to WEB-INF/classes, but that's not the case in my own (functioning) project. Instead, the file is copied to target/classes as per Maven-standard.
它已复制到 target/yourapp/WEB-INF/classes
,但不是 process-resources
默认情况下,m2eclipse 在资源更改时调用它(此目标将资源复制/过滤到 target/classes
)。这发生在package
期间阶段(或显式调用 war:war
、 war:inplace
或 war:exploded
时)。正如 usage 中所述页,WAR 插件不负责编译 java 源代码或复制资源。
所以我建议 package
之前在服务器上运行它的 war 。也许您可以将 m2eclipse 配置为在资源更改时自动执行此操作(右键单击您的项目,然后选择属性 > Maven 并将适当的 war
目标添加到< strong>资源更改时调用的目标)。不过没有尝试过。
关于java - Spring ContextLoader 找不到 applicationContext.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2191123/