0

I have a problem with inject properties in my @Component class

@Configuration
@ComponentScan("my.package.*")
@PropertySource("classpath:setting.properties")
public class PropertiesWithJavaConfig {

@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
  return new PropertySourcesPlaceholderConfigurer();
  }
}

Component class

@Component
public class Why {
@Value("${sc.ws.user}")
private  String user;

public  void  testProperties(){
    System.out.println(user);
  }
}

Initial class for testing

Why w = new Why();
w.testProperties();

Thanks for help

luprogrammer
  • 155
  • 1
  • 3
  • 12
  • 2
    `Why w = new Why();` gives you an instance not managed by spring.. so no `@Value` for `w` –  Feb 06 '15 at 15:58
  • 2
    see http://stackoverflow.com/questions/10997092/autowiring-in-spring-bean-component-created-with-new-keyword –  Feb 06 '15 at 15:59
  • `@Autowired` and `@Value` are more or less the same. If your object isn't a Spring bean, Spring won't have processed it. – Sotirios Delimanolis Feb 06 '15 at 16:14

0 Answers0