在spring @component类中注入@Value

时间:2015-02-06 15:55:57

标签: java spring

我在@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();

感谢您的帮助

0 个答案:

没有答案