Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Vaadin + AspectJ + Spring working only with SerialID generated right before

Cristiano Fontes
1 decade ago Aug 26, 2011 5:12pm

Hi I am using Spring 3 + Spring MVC (half of the site) + Vaadin + AspectJ + JPA2 + Spring Security

My problem is that Spring creates all my Repositories and I would like to share those with Vaadin using AspectJ injection with Spring Annotations, when vaadin is started (Admin part of the site)

I have managed to make it all working after a couple days, I can use the @Configurable Spring annotation in my Vaadin Controller so It can get auto injected with my Spring context repositories,

BTW I am using Compile-Time weaving with maven, codehaus plugins and AspectJ eclipse plugin so tomcat can get the necessary libs.

BUT...

It sometimes works sometimes doesn't...

I found that when I add serializable interface to my repos it works, but only If I ask to generate the serialID and then run the app (tomcat) right after it, if I make any changes and build it again, injection is gone.
My config and Classes...

part that I think matters of my 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

here is the 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();
}
}

My Repo

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....

}

Web.xml with the servlet routings and other stuff.

<?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>

Last updated on Aug, 26th 2011
Eduardo Frazão
1 decade ago Dec 08, 2011 10:34pm