Maven 将 applicationContext.xml 从 src/main/resources 复制到 target/myproject/WEB-INF
目前,我认为默认情况下,它
target/myproject/WEB-INF/classes
在部署时复制到 so 不会获取上下文。
另外,我想引用服务器特定的配置文件database.properties,我想将其放入tomcat/conf中,然后在applicationContext.xml中引用它,我该如何这样做吗?
另外(2),我的印象是这是一种相当标准和体面的设置方式 - 如果我错了,请纠正我。
编辑 对于服务器特定的配置文件我使用这个
<context:property-placeholder
location="file:${catalina.home}/conf/database.properties"
ignore-unresolvable="true"
/>
At the moment, the default I think, it copies to
target/myproject/WEB-INF/classes
so when deploying it does not pick up the context.
Also, i want to reference a server specific config file database.properties, I want to put it in tomcat/conf and then reference it in applicationContext.xml, how can I do this ?
Also(2), I am under the impression that this is a fairly standard and decent way to set things up - please correct me if I am wrong.
edit
for the server specific config file I user this
<context:property-placeholder
location="file:${catalina.home}/conf/database.properties"
ignore-unresolvable="true"
/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您需要将
applicationContext.xml
保留为类路径资源,则可以通过将以下行添加到web.xml< 来配置
ContextLoaderListener
以从类路径中选取它/code>:比配置Maven将其复制到
WEB-INF
要容易得多。关于第二个问题,您可以配置
PropertyPlaceholderConfigurer
或
从文件系统加载.properties
文件。If you need to keep
applicationContext.xml
as a classpath resource, you can configureContextLoaderListener
to pick it from the classpath by adding the following lines toweb.xml
:It's much easier than configuring Maven to copy it to
WEB-INF
.Regarding the second question, you can configure
PropertyPlaceholderConfigurer
or<context:property-placeholder>
to load.properties
file from a file system.对于您的标题问题:通常在 .war maven 模块中,您会将与 Web 相关的资源放在 src/main/webapp 下,而不是 src/main/resources 下。然后 Maven 插件会自动拾取它们,因为它符合约定。因此,将 applicationContext.xml 移动到 src/main/webapp/WEB-INF
另一种选择是按照 文档
对于第二个问题,您可以查看 PropertyPlaceHolderConfigurer。您只需要确保路径正确即可。
For your title question: Often in a .war maven module, you'll put web related resources under src/main/webapp instead of src/main/resources. Then the maven plugin will pick them up automatically because it matches convention. So, move your applicationContext.xml to src/main/webapp/WEB-INF
Another option is to configure the webResources as described in the documentation
For the second question you can look at a PropertyPlaceHolderConfigurer. You'll just have to get the path correct.