How can I change the default location of log4j2.xml in Java Spring Boot?

后端 未结 6 1308
醉梦人生
醉梦人生 2020-12-14 09:37

Log4j2 is working nicely with Spring Boot through the log4j2.xml configuration file in the root classpath, exactly as the documentation states.

When try

6条回答
  •  攒了一身酷
    2020-12-14 09:57

    I have the same problem in my project, besides log4j2.xml I also need other config files in the class path. Here is my 2 solutions that works:

    Soluation 1 : Start spring boot application with org.springframework.boot.loader.JarLauncher

    java -classpath SpringBootProject.jar;./config org.springframework.boot.loader.JarLauncher
    

    Solution 2: Write a './config' class path entry in the MANIFEST.MF in the jar

        
        
          
            maven-jar-plugin
            
              
                
                   ./config/
                
              
            
          
          
            org.springframework.boot
            spring-boot-maven-plugin
            1.5.3.RELEASE
            
              
                
                  repackage
                
              
            
          
        
      
    

提交回复
热议问题