I have two maven module:
logic (Spring project with beans etc.) - packed to .jar
Web (Vaadin project with spring nature) - packet to .war
In Web .pom I have dependecy to logic. In java code autowired etc. is ok. I want use beans from logic in Web project.
My web.xml (Web project): path: ../src/main/webapp/WEB-INF
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml
</param-value>
</context-param>
My application context: (path: ../src/main/webapp/WEB-INF)
<beans ...
<context:annotation-config />
<import resource="logic.xml"/>
<context:component-scan base-package="b2b"
annotation-config="true" />
logic.xml contains configuration for beans in logic module. Base package name is b2b.
In UI class I have:
@Autowired
private CompanyService companyService;
I try in many ways to get beans, but always companyService is null after start Web.
What I should add to get beans from logic module visible in Web module?
UI class:
@Theme("mytheme")
@SuppressWarnings("serial")
@Controller
public class MyVaadinUI extends UI
{ }
I also make as mentions here for vaadin V7: enter link description here
but not help.
This is my UI class:
enter code here
@Theme("mytheme")
@SuppressWarnings("serial")
@Controller
public class MyVaadinUI extends UI
{
SpringContextHelper helper = new SpringContextHelper(VaadinServlet.getCurrent().getServletContext());
private static Logger LOGGER = Logger.getLogger(MyVaadinUI.class);
@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = MyVaadinUI.class, widgetset = "b2b.frontend.AppWidgetSet")
public static class Servlet extends VaadinServlet {
}
@Override
protected void init(VaadinRequest request) {
final VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
setContent(layout);
final CompanyService companyService = (CompanyService) helper.getBean("companyService");
Button button = new Button("Click Me");
button.addClickListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
//layout.addComponent(new Label("Thank you for clicking"));
LOGGER.info("pushed the button");
layout.addComponent(new Label("aa " +companyService +" Thank you for clicking"));
}
});
layout.addComponent(button);
}
}