Reputation: 1916
@Configuration
public class WebAppConfig extends WebMvcConfigurerAdapter {
@Bean
AuthorizeInterceptor authorizelInterceptor() {
return new AuthorizeInterceptor();
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(authorizelInterceptor()).addPathPatterns("/user/**");
super.addInterceptors(registry);
}
}
I think @Bean
will put the new AuthorizeInterceptor();
into IOC and in method addInterceptors()
call authorizelInterceptor()
will get the bean registered in IOC. if use proxy, method authorizelInterceptor()
called in addInterceptors()
will not do proxy.
Upvotes: 0
Views: 178
Reputation: 22442
@Bean is a method level annotation which simply provides the bean configuration to the Spring container and the container uses it to inject the respective dependency. In short,it is just alternative to defining the bean using xml <bean/>
tags.
I generally use @Bean while writing the simple unit tests, to provide the bean definitions in the same Test class file (rather than defining a separate xml for bean configurations).
I recommend you to go through the below link for more details:
http://docs.spring.io/spring-javaconfig/docs/1.0.0.M4/reference/html/ch02s02.html
Upvotes: 1