私は2つのmavenモジュールを持っています:
ロジック (Bean などを使用した Spring プロジェクト) - .jar にパック
Web (春の性質を持つ Vaadin プロジェクト) - .war へのパケット
Web .pom では、ロジックに依存しています。Java コードでは autowired などは問題ありません。Web プロジェクトでロジックから Bean を使用したい。
私の web.xml (Web プロジェクト): パス: ../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>
私のアプリケーション コンテキスト: (パス: ../src/main/webapp/WEB-INF)
<beans ...
<context:annotation-config />
<import resource="logic.xml"/>
<context:component-scan base-package="b2b"
annotation-config="true" />
logic.xml には、ロジック モジュールの Bean の構成が含まれています。基本パッケージ名は b2b です。
UIクラスには次のものがあります:
@Autowired
private CompanyService companyService;
私はさまざまな方法で Bean を取得しようとしますが、Web を開始した後は常に companyService が null になります。
ロジック モジュールの Bean を Web モジュールで表示するには、何を追加すればよいですか?
UI クラス:
@Theme("mytheme")
@SuppressWarnings("serial")
@Controller
public class MyVaadinUI extends UI
{ }
ここで vaadin V7 についても言及しています。ここにリンクの説明を入力してください
しかし、助けにはなりません。
これは私のUIクラスです:
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);
}
}