繁体   English   中英

与Vaadin的Spring集成不起作用

[英]Spring integration with Vaadin doesn't work

我正在尝试将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

由于我可以看到所需的对象,例如UserManagermainWindow ...

但是,当涉及到实际注射时,它似乎不起作用。 我得到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之前没有错误消息。

有人知道怎么了吗?

谢谢。

您可能应该使用插件在Vaadin中使用Spring 链接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM