我正在尝试使用注释加载属性:
@PropertySource({"classpath:application.properties"})和
@Value("${my.property}")
String myProperty;因此,myProperty始终为null
当它工作时,使用:
BatchConfiguration.class.getClassLoader().getResourceAsStream("application.properties");这是我的Batch conf类签名:
@Configuration
@ComponentScan
@EnableBatchProcessing
@PropertySource({"classpath:application.properties"})
public class BatchConfiguration {
@Value("${db.url}")
private String url;
...
}和Application.java:
@SpringBootApplication
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}我还尝试使用以下命令加载它:
@Autowired
public static Environment env;但是env也是空的。
发布于 2019-10-16 17:44:10
在运行Spring引导应用程序时传递以下JVM参数
--spring.config.location=properties file path发布于 2019-10-16 17:42:24
在你的@PropertySource({"classpath:application.properties"})中删除{},应该是
@PropertySource("classpath:application.properties")或
@PropertySource(value="classpath:application.properties")https://stackoverflow.com/questions/58409990
复制相似问题