When not used before production environment and so on, the problem encountered is when I need to modify my code inside the variable, you need to modify the overall, global variables do not think write in application.properties, but it in this case the need for other conponent notes to class up
indexPath=D:/lucene_index/happy6
@Component
public class ConstantInPro {
@Value("${indexPath}")
String Path;
public String getPath() {
return Path;
}
}
This is somewhat troublesome, back to the professor asked, proposed the production of different environments, the need for major structural
Then we need to write about this in the config class:
package com.etc.newmoudle.Config;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
/**
* author:langlang
* data: 2020-01-08 10:11
*/
@Configuration
public class SysEnv implements EnvironmentAware {
/**
* 项目环境
*/
public static String active;
/**
* 启动端口
*/
public static String port;
/**
* 项目上下文路径
*/
// public static String contextPath;
@Override
public void setEnvironment(Environment environment) {
active = environment.getProperty("spring.profiles.active");
// port = environment.getProperty("server.port");
// contextPath = environment.getProperty("server.servlet.context-path");
}
}