2012-03-14 8 views
2

vaadinアプリケーションで@ 3つの@Autowireアノテーションを使用する際に問題があります。VaadinとSpringのセットアップ3 - 自動配線が失敗する(注釈)

私は、オートワイヤードサービスクラスのメソッドを実行するボタンだけで、小さなテストプロジェクトを作成しました。

サービスが挿入されないため、ボタンをクリックするとNullPointerExceptionが発生します。

私はこれは私のアプリケーションクラスである@Service( "calculationService")

でサービスを注釈を付けている

package vaadinBaas; 

// imports 

public class MyVaadinApplication extends Application { 

private Window window; 

private CalculationService calculationService; 

@Autowired 
public void setCalculationService(CalculationService calculationService) { 
    this.calculationService = calculationService; 
} 

@Override 
public void init() { 
    window = new Window("Show me the magic"); 
    setMainWindow(window); 

    Button button = new Button("Click Me"); 

    button.addListener(new Button.ClickListener() { 
     public void buttonClick(ClickEvent event) { 
      window.addComponent(new Label(String.valueOf(calculationService.multiply(10, 10)))); 
     } 
    }); 

    window.addComponent(button); 
} 
} 

は、これは私の春のアプリケーションコンテキストである:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:ct="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 

    http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context.xsd"> 

<ct:component-scan base-package="vaadinBaas" /> 
<ct:annotation-config /> 

<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/> 
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"/> 
</beans> 

そして最後に私のweb.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    id="WebApp_ID" version="2.5"> 
<display-name>Vaadin Web Application</display-name> 

<context-param> 
    <description>Vaadin production mode</description> 
    <param-name>productionMode</param-name> 
    <param-value>false</param-value> 
</context-param> 

<servlet> 
    <servlet-name>Vaadin Application Servlet</servlet-name> 
    <servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class> 
    <init-param> 
     <param-name>application</param-name> 
     <param-value>vaadinBaas.MyVaadinApplication</param-value> 
    </init-param> 
</servlet> 

<servlet-mapping> 
    <servlet-name>Vaadin Application Servlet</servlet-name> 
    <url-pattern>/*</url-pattern> 
</servlet-mapping> 

<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> 
</web-app> 

私はここで何かが分かりませんか?

+0

は**同じパッケージ内の** CalculationService **です。vaadinBaas **? – ManuPK

+0

サブパッケージ "services"にあります。 – geoffreydv

答えて

1

MyVaadinApplicationにコンポーネント注釈を付けることを試みてください。 MyVaadinApplicationはSpring管理クラスとはみなされないので、Autowireはあなたのために機能しませんでした。また、ClassPathXmlApplicationContextを使用してBean定義XMLをロードして、すべての自動配線が自動的に行われるようにgetBean(MyVaadinApplication.class)を呼び出す必要があります。

関連する問題