spring boot-1.4.2 jar启动使用外部application.properties

一、使用@PropertySource

注意:请将application.properties和jar包放在同一目录下,

运行cmd,打开命令行窗口,执行E:\>java -jar securitydemo-1.0.jar

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.PropertySource;

@SpringBootApplication
@PropertySource(value={"file:E:\\application.properties"})
public class App  
{
    private static Logger log = LoggerFactory.getLogger(App.class);
    public static void main( String[] args )
    {   
        SpringApplication.run(App.class, args);
        log.info("项目启动:{}","I'am start;");
    }

}


二、不使用@PropertySource,启动jar包时指定spring.config.location

java  -jar  -Dspring.config.location=E:\application.properties   securitydemo-1.0.jar

你可能感兴趣的:(spring,boot-1.4.2)