loading of property file outside of war file in spring boot

anavaras lamurep

I need to load the application.properties file from outside the spring boot war which going to be deployed in tomcat.

I tried various solution missing something

  1. Tried setting environmental variable as below in windows

    name : SPRING_CONFIG_NAME value:D:/test/application.properties

i tried multiple values for above value like file:/// in prefix and only file: as perfix .Nothing worked

  1. Tried having context parameter is tomcat like mentioned in below SO answer https://stackoverflow.com/a/44697239/2751962

  2. Tried loading like this in main file which extends SpringBootServletIntializer

    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(Application.class) .properties(getProperties()); }

     public static void main(String[] args) throws Exception {
                    SpringApplication.run(Application.class, args);
    
                     SpringApplicationBuilder springApplicationBuilder = (SpringApplicationBuilder) (new SpringApplicationBuilder(Application.class))
                     .sources(Application.class)
                     .properties(getProperties())
                     .run(args);
    
    
                }
    
                static Properties getProperties() {
                    Properties props = new Properties();
                    props.put("spring.config.location", "file:///D:/test/application.properties​");
                    return props;
                }
    

I not sure what i missed , Kindly help.

Tarun

You can try setting properties via XML and or Java configuration and @PropertySource.

@Configuration
@PropertySource("classpath:foo.properties")
public class PropertiesWithJavaConfig {
    //...
}

source :- https://www.baeldung.com/properties-with-spring

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Spring Boot War-File not working on Tomcat

How is a war file created for spring boot with maven?

serving files from a spring boot war file

Spring boot override suffix of war file name

Spring boot war file deploy on Tomcat

Accessing property file in spring boot

Spring Boot 2.0 JNDI property values not loading from application-test property file

Spring read property file outside the class path

Update Spring Boot to generate WAR file instead of JAR file

Spring boot is not loading bootstrap.properties file

Spring Boot war file on tomcat: errorPageFilter cannot be cast to TomcatEmbeddedServletContainerFactory

Deploy WAR file on Tomcat of Spring boot and Angular App

How to specify a profile when deploying a Spring boot war file to Tomcat?

where to put text file in war packing spring boot

Why spring boot generates jar or war file with .original extension?

Spring boot app vs .war file deployed on Tomcat/Jetty

Create war file from Spring:boot project in Eclipse

Spring Boot & Thymeleaf static content not served in war file

Spring Boot Gradle - avoid lib-provided folder in war file

Spring boot app with web.xml in the .war file

Spring Boot war file works with embedded but not with standalone Tomcat

spring boot maven how to build both war and jar file

Deploying standalone war file from Spring Boot to Jetty

Java Spring Boot - war file not deploying on Tomcat Apache

generating a working war file with maven for a spring-boot web application

How to run external war file with embedded tomcat of spring boot with gradle?

Generating a Spring Boot WAR file with datasource properties predefined failing to deploy

Spring Boot REST API war file generating 404 error

java spring boot - war file is not deploying on Apache Tomcat

TOP Ranking

HotTag

Archive