Spring Dependency Injection を Vaadin に統合しようとしていますapplication/servlet
。ただし、依存性注入は機能しません。Spring はコンポーネントをうまく読み取ると思います。
2013-01-15 06:57:11,361 [localhost-startStop-1] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [com/nortal/pirs/spring/application-context.xml]
2013-01-15 06:57:12,012 [localhost-startStop-1] INFO org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@fa5214b: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.config.internalBeanConfigurerAspect,mainController,UserManager,VisitManager,mainWindow,org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor#0,org.springframework.context.annotation.CommonAnnotationBeanPostProcessor#0,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy
のような必要なオブジェクトが表示されるのでUserManager
、mainWindow
...
しかし、実際に注入してみると、うまくいかないようです。私はそれでnullpointerexceptionsを取得します。
今、私はそれをテストしようとしています。注入MainWindow
する必要があるアプリケーションは次のとおりです。MainWindow
@Configurable
public class PirsVaadinController extends Application implements
NavigatorInterface {
private String title = "WELCOME";
private transient Logger log;
private Map userData;
private boolean useFakeData = false;
@Autowired
private MainWindow mainWindow;
public UserManagerInterface getUserManager() {
return userManager;
}
@Autowired
public void setUserManager(UserManagerInterface userManager) {
this.userManager = userManager;
}
はい@Autowired
、セッターと変数自体の両方を配置していることはわかっていますが、どちらの方法でも機能しません。
メインウィンドウ:
@org.springframework.stereotype.Component
@org.springframework.context.annotation.Scope("session")
public class MainWindow extends Window {
私のweb.xml:
<!-- Vaadin -->
<context-param>
<description>Vaadin production mode</description>
<param-name>productionMode</param-name>
<param-value>true</param-value>
</context-param>
<servlet>
<servlet-name>PirsVaadinFrontend</servlet-name>
<servlet-class>
com.vaadin.terminal.gwt.server.ApplicationServlet
</servlet-class>
<init-param>
<description>Vaadin application class to start</description>
<param-name>application</param-name>
<param-value>
com.nortal.pirs.presentation.vaadin.PirsVaadinController
</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>PirsVaadinFrontend</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<!-- Spring -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:com\nortal\pirs\spring\application-context.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- EmailCheck REST web service -->
<servlet>
<servlet-name>emailCheckService</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.nortal.pirs.webservices</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>emailCheckService</servlet-name>
<url-pattern>/webservices/*</url-pattern>
</servlet-mapping>
<!-- General parameters -->
<session-config>
<session-timeout>60</session-timeout>
</session-config>
私のSpringアプリケーションコンテキスト:
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="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/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:annotation-config />
<!-- Turn on AspectJ @Configurable support -->
<context:spring-configured />
<context:component-scan base-package="com.nortal.pirs.test.independent" />
<context:component-scan base-package="com.nortal.pirs.businesslogic.logic" />
<context:component-scan base-package="com.nortal.pirs.presentation.vaadin" />
<!-- Turn on @Autowired, @PostConstruct etc support -->
<bean
class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
<bean
class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />
</beans>
私のMaven pom.xml:
<repositories>
<repository>
<id>com.springsource.repository.bundles.release</id>
<name>EBR Spring Release Repository</name>
<url>http:// repository.springsource.com/maven/bundles/release</url>
</repository>
<repository>
<id>com.springsource.repository.bundles.external</id>
<name>EBR External Release Repository</name>
<url>http:// repository.springsource.com/maven/bundles/external</url>
</repository>
</repositories>
<build>
<sourceDirectory>src/</sourceDirectory>
<directory>${basedir}/build</directory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- Additional -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<versionRange>1.2</versionRange>
<goals>
<goal>test-compile</goal>
<goal>compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<!-- Vaadin - Spring -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.2</version>
<configuration>
<!-- Required as the plugin does not resolve this by default -->
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
おそらく文字数制限に達する可能性があるため、依存関係を提供しませんでしたが、依存関係には私見が欠けているようには見えません。pom.xml で、次のエラーが発生します。
Multiple annotations found at this line:
- Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:aspectj-maven-plugin:1.2:test-compile (execution: default, phase:
process-test-sources)
- Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:aspectj-maven-plugin:1.2:compile (execution: default, phase: process-
sources)
しかし、コマンドラインからは、すべてがうまくコンパイルされているようです:
mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building PIRS AMS 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- aspectj-maven-plugin:1.2:compile (default) @ PIRS_AMS_WEB ---
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ PIRS_AMS_W
EB ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Dropbox\EclipseWorkspace\PIRS_FIX\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.1:compile (default-compile) @ PIRS_AMS_WEB --
-
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. b
uild is platform dependent!
[INFO] Compiling 1 source file to D:\Dropbox\EclipseWorkspace\PIRS_FIX\build\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.617s
[INFO] Finished at: Tue Jan 15 07:35:39 EET 2013
[INFO] Final Memory: 16M/309M
[INFO] ------------------------------------------------------------------------
私が言ったように、実際に注入する必要があるポイントまですべてが機能し、前にエラーメッセージは表示されませんnullpointerexception
。
誰が何が悪いのか知っていますか?
ありがとう。