import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
@Configuration
@PropertySources(@PropertySource("classpath:task.properties"))
public class FileConfig {
public static String ON_CHANGE_DIRECTORY;
public static String ON_CHANGE_FILE;
@Value("${spring.onChangeFile}")
public void setOnchangeFile(String onChangeFile) {
FileConfig.ON_CHANGE_FILE = onChangeFile;
}
@Value("${spring.onChangeDirectory}")
public void setOnChangeDirectory(String onChangeDirectory) {
FileConfig.ON_CHANGE_DIRECTORY = onChangeDirectory;
}
public FileConfig() {
}
}
或者
@Configuration
@PropertySources(@PropertySource("classpath:task.properties"))
public class FileConfig {
@Value("${spring.onChangeFile}")
public String onChangeFile;
@Value("${spring.onChangeDirectory}")
public String onChangeDirectory;
public static String ON_CHANGE_DIRECTORY;
public static String ON_CHANGE_FILE;
@PostConstruct
public void intit() {
FileConfig.ON_CHANGE_FILE = onChangeFile;
FileConfig.ON_CHANGE_DIRECTORY = onChangeDirectory;
}
public FileConfig() {
}
}