我在@Component
类
@Configuration
@ComponentScan("my.package.*")
@PropertySource("classpath:setting.properties")
public class PropertiesWithJavaConfig {
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
组件类
@Component
public class Why {
@Value("${sc.ws.user}")
private String user;
public void testProperties(){
System.out.println(user);
}
}
测试的初始课程
Why w = new Why();
w.testProperties();
感谢您的帮助