Vaadin中的AspectJ注入仅在我生成SerialVersionuID之后才起作用

时间:2011-08-26 16:39:49

标签: spring spring-mvc dependency-injection aspectj vaadin

您好我使用Spring 3 + Spring MVC(网站的一半)+ Vaadin + AspectJ + JPA2 + Spring Security

我的问题是Spring创建了我的所有存储库,并且当vaadin启动时,我想使用带有Spring Annotations的AspectJ注入与Vaadin共享这些存储库(网站的管理员部分)

我已经设法让它在几天后全部工作了,我可以在我的Vaadin控制器中使用@Configurable Spring注释,这样它就可以自动注入我的Spring上下文库,

BTW我正在使用编译时编织maven,codehaus插件和AspectJ eclipse插件,因此tomcat可以获得必要的库。

但是...

有时候工作有时不会......

我发现当我向我的repos添加可序列化接口时,它可以工作,但只有当我要求生成serialId然后在它之后运行应用程序(tomcat)时,如果我进行任何更改并再次构建它,注射消失了。

我的配置和课程......

部分我认为我的applicationContext.xml

   .
   .
   Other stuff

    <context:spring-configured />
    <context:component-scan base-package="br.com.gsc" />
    <mvc:annotation-driven />
    <tx:annotation-driven transaction-manager="transactionManager"/>

   .
   .
   Other stuff

这里是Vaadin Servlet

package br.com.gsc.vaadin;

import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;

import br.com.gsc.model.tableMapping.Person;
import br.com.gsc.repository.objRepos.PersonRepository;

import com.vaadin.Application;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.Window;


@Configurable(preConstruction=true,autowire=Autowire.BY_TYPE)
public class VaadinOperatorServlet extends Application {


/**
     * 
     */
    private static final long serialVersionUID = -1481084776783567319L;

    @Autowired
    private transient PersonRepository pRepo;

    public void init() {
        createWindow();
    }

    public void createWindow(){
        Window window = new Window();
        Panel p = new Panel();
        Label l = new Label("Teste");
        Label l2 = new Label("");
        Label l3 = new Label("");

        Person person = pRepo.findPersonByID("user");
        l2 = new Label(person.getUsername());
        p.addComponent(l);
        p.addComponent(l2);
        window.addComponent(p);
        setMainWindow(window);
        window.getContent().setSizeFull();  
    }
}

我的回购

package br.com.gsc.repository.objRepos;

import java.io.Serializable;
import java.util.List;

import org.springframework.stereotype.Repository;

import br.com.gsc.model.tableMapping.Person;
import br.com.gsc.repository.AbsRepository;
import br.com.gsc.repository.objInterfaces.IPersonRepository;

@Repository
public class PersonRepository extends AbsRepository<Person> implements IPersonRepository,Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = -8520715359024018210L;

    @Override
    public void addPerson(Person t) {
        add(t);
    }

    Lot's of other stuff....



}

带有servlet路由和其他东西的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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    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>GSC</display-name>
    <welcome-file-list>
        <welcome-file>/intern.html</welcome-file>
    </welcome-file-list>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

      <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
      </listener>

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

<!--    SERVLETS     -->
    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>    
    <servlet>
        <servlet-name>vaadinServlet</servlet-name>
        <servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
        <init-param>
            <param-name>application</param-name>
            <param-value>br.com.gsc.vaadin.VaadinOperatorServlet</param-value>
        </init-param>
        <init-param>
            <description>Application widgetset</description>
            <param-name>widgetset</param-name>
            <param-value>br.com.gsc.vaadin.widgetset.GscWidgetset</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

<!--    SERVLET MAPPINGS -->
    <servlet-mapping>
        <servlet-name>vaadinServlet</servlet-name>
        <url-pattern>/admin/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>vaadinServlet</servlet-name>
        <url-pattern>/oper/*</url-pattern>
    </servlet-mapping>   
    <servlet-mapping>
          <servlet-name>vaadinServlet</servlet-name>
          <url-pattern>/VAADIN/*</url-pattern>
    </servlet-mapping> 
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>        

<!--  Filter OpenSession     -->   
    <filter>  
      <filter-name>openEntityManager</filter-name>   
      <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>   
    </filter>  
    <filter-mapping>  
      <filter-name>openEntityManager</filter-name>   
      <url-pattern>/*</url-pattern>   
    </filter-mapping>  
<!--  Filter OpenSession  -->

    <!--  Filter Security  -->
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!--  Filter Security -->

    <!-- Filter HTTP Methods -->
    <filter>
        <filter-name>httpMethodFilter</filter-name>
        <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>httpMethodFilter</filter-name>
        <servlet-name>spring</servlet-name>
    </filter-mapping>
    <!-- Filter HTTP Methods -->
</web-app>

2 个答案:

答案 0 :(得分:1)

听起来像我们遇到的问题,我们已正确配置maven编译时编织@ Configurable,但Eclipse并没有自动执行此操作。 这是eclipse中m2eclipse插件的一个特性,我认为这是缺乏的。 因为你在pom文件中的方面路径中正确定义了spring-aspects jar,但是eclipse也不知道这样做。 因此,我们必须手动将AOP facet添加到包含@Configurables的项目中,然后将其配置为添加spring-aspects.jar作为aspect路径。 然后当eclipse编译时,方面被编织,当你从Eclipse运行你的tomcat时,你的tomcat将使用编织类,而不是非编织类。

答案 1 :(得分:0)

我无论如何都无法解决它......

我终于使用Spring roo构建了一个maven web应用程序并将所有代码和配置粘贴在那里,因为我知道Roo与Aspects一起开箱即用。

它现在正在工作......但是我不知道为什么我的上一个项目在Spring Context之外的DI中遇到了这个问题。