我想添加spring mvc拦截器作为Java配置的一部分.我已经有一个基于xml的配置,但我正在尝试转向Java配置.对于拦截器,我知道可以从弹簧文档中这样做 -
@EnableWebMvc
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LocaleInterceptor());
}
}
Run Code Online (Sandbox Code Playgroud)
但我的拦截器正在使用一个自动装入其中的弹簧豆,如下所示 -
public class LocaleInterceptor extends HandlerInterceptorAdaptor {
@Autowired
ISomeService someService;
...
}
Run Code Online (Sandbox Code Playgroud)
SomeService类如下所示 -
@Service
public class SomeService implements ISomeService {
...
}
Run Code Online (Sandbox Code Playgroud)
我正在使用注释@Service来扫描bean,并且没有在配置类中指定它们@Bean
据我所知,由于java配置使用new来创建对象,因此spring不会自动将依赖项注入其中.
我如何添加这样的拦截器作为java配置的一部分?