0

I want use environment property in MyLoginSuccessHandler class that is used in SpringSecurity.

You know, MyLoginSuccessHandler implements AuthenticationSuccessHandler.

But, most examples show usage of @autowired like below.

@Autowired
private Environment env;

But autowired env variable is null. Because this is login success handler not controller.

I wish to know initialize environment object without @Autowired annotation. I want to use env object to access a property in application.yml.

If you are alright, please describe how @Autowired works. Sometimes I face such this situation, but I do not know how it works.

Thanks.

Hyeong-woo
  • 29
  • 6
  • It doesn't matter if it is a controller or not. The important part is that it needs to be a spring managed bean. If it is isn't dependencies won't be injected. – M. Deinum Jan 27 '19 at 13:32
  • `Environment` is a bean in spring,you can use `@Autowired` to auto inject or use `SpringContext.getBean(name)` to get. – TongChen Jan 27 '19 at 13:33
  • Do you use `Environment` class to read properties? – void Jan 27 '19 at 13:35

0 Answers0