【发布时间】:2013-06-10 09:26:32
【问题描述】:
我正在尝试创建一个可以使用弹簧属性文件的 WAR,但我似乎遇到了一些问题。
我可以在目标的基本目录结构中看到我的属性文件,当我进行爆炸战争时,我可以在 WAR 中看到我的属性文件。但是,当我尝试制作正常的 WAR 并进行部署时,我发现资源未找到异常,具体来说:
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [service.properties] cannot be opened because it does not exist
从码头我没有这样的问题。
这是我对资源的spring java配置:
@Bean
public static PropertySourcesPlaceholderConfigurer propertyPlaceHolderConfigurer() {
PropertySourcesPlaceholderConfigurer props = new PropertySourcesPlaceholderConfigurer();
props.setLocations(new Resource[] { new ClassPathResource("service.properties") });
return props;
}
这是我的 POM 的相关部分。我在 WAR 配置中添加了因为 maven 似乎要这样做here,但它似乎没有帮助。
<build>
<resources>
<resource>
<directory>src/main/config/local</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<goals>
<goal>war</goal>
</goals>
<configuration>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>src/main/config/local</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
有人知道我做错了什么吗?谢谢!
【问题讨论】:
标签: java spring properties war