0

I am using jasypt-spring-boot-starter:1.14 along with spring-boot-2.0.0.M2

It works perfectly fine if the application.properties is available in the classpath ( src/main/resources )

Spring boot will work even if the application.properties is placed in the folder from where the spring boot jar is run ( by default it looks for application.properties in the current folder)

If I move the application.properties out of src/main/resources and place it in the root folder , the application fails to start with the below error

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]

I was able to run other spring boot jars by placing the application.properties in the folder from where spring boot is run. But after integrating with jasypt , it is not working

Kindly revert if any body has faced such issue

lives
  • 1,243
  • 5
  • 25
  • 61
  • You can check out spring boot jasypt implmentation : https://github.com/ulisesbocchio/jasypt-spring-boot-samples/tree/master/jasypt-spring-boot-demo – Yogi Nov 07 '17 at 16:27
  • In the example shared , the application.properties is placed in src/main/resources folder. That works fine. When I move it out to the folder from where the boot jar is run , that's when it fails. – lives Nov 08 '17 at 05:04

1 Answers1

0

You have to resolve the config path manually. Sample implementation below where myapp.home is an application argument (or VM option -> -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;
    }

    ...
}
alltej
  • 6,787
  • 10
  • 46
  • 87