Здравствуйте, я интегрировал Spring and Vaadin 7, но @Inject у меня работает только в главном классе AdminPanelMain
| Код | @Component @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) @PreserveOnRefresh @Slf4j public class AdminPanelMain extends UI {
@Inject //It works private UserService userService;
private static final long serialVersionUID = 1L;
// @Inject private Panel tagsPanel = new TagsPanel();
|
UserService Service - просто тестовый класс.
| Код | @Service @Slf4j public class UserService {
// @Autowired // private UserRepository userRepository;
public void saveUser() {
// log.info("count: {}", userRepository.count()); log.warn("saved"); } }
|
TagsPanel - хочу и здесь иметь сервис, но он нуль, так же как и в других похожих компонентах.
| Код | public class TagsPanel extends Panel implements Property.ValueChangeListener {
private static final long serialVersionUID = 1L;
@Autowired //null private UserService userService;
public TagsPanel() {
initLayout();
} ....... }
|
ApplicationInitializer
| Код | public class ApplicationInitializer implements WebApplicationInitializer {
@Override public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(ApplicationConfiguration.class); registerSpringContextLoaderListener(servletContext, rootContext); registerVaadinServlet(servletContext, rootContext); }
private void registerVaadinServlet(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
VaadinServlet vaadinServlet = new VaadinServlet(); ServletRegistration.Dynamic vaadinServletRegistration = servletContext.addServlet("vaadinServlet", vaadinServlet); vaadinServletRegistration.setInitParameter("ui", AdminPanelMain.class.getName()); vaadinServletRegistration.setInitParameter("UIProvider", SpringUIProvider.class.getName()); vaadinServletRegistration.setLoadOnStartup(1); vaadinServletRegistration.addMapping("/*");
}
private void registerSpringContextLoaderListener(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) { servletContext.addListener(new ContextLoaderListener(rootContext)); servletContext.addListener(new ContextCleanupListener()); servletContext.addListener(new RequestContextListener()); } }
|
Когда я создаю объект TagsPanel, то объект UserService=null - почему?
Спасибо за помощь. |