我正在使用 jasypt-spring-boot-starter:1.14 以及 spring-boot-2.0.0.M2
如果application.properties在类路径中可用(src / main / resources),那么它的工作完全正常
即使将application.properties放在运行spring boot jar的文件夹中(默认情况下它在当前文件夹中查找application.properties),Spring启动也会有效。
如果我将application.properties移出src / main / resources并将其放在根文件夹中,则应用程序无法启动以下错误
nested exception is java.io.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:179) ~[spring-context-5.0.0.RC2.jar!/:5.0.0.RC2]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:308) ~[spring-context-5.0.0.RC2.jar!/:5.0.0.RC2]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:229) ~[spring-context-5.0.0.RC2.jar!/:5.0.0.RC2]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:271) ~[spring-context-5.0.0.RC2.jar!/:5.0.0.RC2]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94) ~[spring-context-5.0.0.RC2.jar!/:5.0.0.RC2]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:686) ~[spring-context-5.0.0.RC2.jar!/:5.0.0.RC2]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:524) ~[spring-context-5.0.0.RC2.jar!/:5.0.0.RC2]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:122) ~[spring-boot-2.0.0.M2.jar!/:2.0.0.M2]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.0.0.M2.jar!/:2.0.0.M2]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) [spring-boot-2.0.0.M2.jar!/:2.0.0.M2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.0.M2.jar!/:2.0.0.M2]
我可以通过将application.properties放在运行spring boot的文件夹中来运行其他spring boot jar。 但是在与jasypt集成后,它无法正常工作
如果任何机构遇到此类问题,请退回
答案 0 :(得分:0)
您必须手动解析配置路径。下面的示例实现,其中myapp.home
是应用程序参数(或VM选项 - > -Dmyapp.home=c:\my_app
)
@Configuration
public class Config {
...
@Bean
private static PropertyPlaceholderConfigurer getCustomPropertyPlaceholderConfigurer() {
String appPropertyFile = "application.properties";
String myAppHome = System.getProperty("myapp.home") + + File.separatorChar + "conf";;
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
final Resource extResource = new FileSystemResource( new File( myAppHome, appPropertyFile) );
ppc.setLocations( new Resource[] { extResource } );
ppc.setIgnoreUnresolvablePlaceholders( true );
return ppc;
}
...
}