Hi!
I’m trying to get a simple vaadin project working with spring as explained in
spring wiki
.
My context.xml
<?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:jee="http://www.springframework.org/schema/jee"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<!-- Data classes -->
<bean id="userDao"
class="com.collapsux.filer.datalevel.impl.UserDaoImpl">
</bean>
<bean id="logDao"
class="com.collapsux.filer.datalevel.impl.FilerLogDaoImpl">
</bean>
<!-- Service components -->
<bean id="filerService"
class="com.collapsux.filer.services.impl.FilerServiceImpl">
<property name="userDao">
<ref bean="userDao" />
</property>
<property name="logDao">
<ref bean="logDao" />
</property>
</bean>
<!-- Database connection -->
<bean id="datasource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:mem:filer" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
<!-- JPA-definitions -->
<!-- Factory for entitymanagers -->
<bean id="emf"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="datasource" />
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
</bean>
<!-- Notice @PersistenceContext-annotations -->
<context:annotation-config />
<!-- Transaction management -->
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory"
ref="emf" />
</bean>
<!-- Notice @Transactional annotations -->
<tx:annotation-driven />
<!-- Turn on AspectJ @Configurable support -->
<context:spring-configured />
<context:component-scan base-package="com.collapsux.filer" />
<!-- Turn on @Autowired, @PostConstruct etc support -->
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />
</beans>
and my web.xml contains this:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:context.xml</param-value>
</context-param>
My main class starts:
@Configurable(preConstruction = true)
public class FilerApplication extends Application
{
private static final long serialVersionUID = 6777561160414111445L;
public static final String VERSION = "1.0";
@Autowired
private FilerService service;
private User currentUser;
private Window mainWindow;
private Panel mainPanel;
@Override
public void init()
{
mainWindow = new Window("Filer " + VERSION);
try {
service.importDataToDatabase("C:/dev/workspace/filer-services/database_export.xml");
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
but when I run mvn:tomcat run, it gives me this:
C:\dev\workspace\filer-ui-vaadin>mvn tomcat:run
[INFO]
Scanning for projects...
[INFO]
------------------------------------------------------------------------
[INFO]
Building Vaadin Web Application
[INFO]
task-segment: [tomcat:run]
[INFO]
------------------------------------------------------------------------
[INFO]
Preparing tomcat:run
[INFO]
[aspectj:compile {execution: default}]
[WARNING]
bad version number found in C:\Documents and Settings\kj\.m2\repositor
y\org\aspectj\aspectjrt\1.6.1\aspectjrt-1.6.1.jar expected 1.6.3 found 1.6.1
[INFO]
[resources:resources {execution: default-resources}]
[INFO]
Using 'UTF-8' encoding to copy filtered resources.
[INFO]
skip non existing resourceDirectory C:\dev\workspace\filer-ui-vaadin\src\
main\resources
[INFO]
[compiler:compile {execution: default-compile}]
[INFO]
Nothing to compile - all classes are up to date
[INFO]
[tomcat:run {execution: default-cli}]
[INFO]
Running war on http://localhost:8080/filer-ui-vaadin
[INFO]
Using existing Tomcat server configuration at C:\dev\workspace\filer-ui-v
aadin\target\tomcat
14.7.2010 21:34:43 org.apache.catalina.startup.Embedded start
INFO: Starting tomcat server
14.7.2010 21:34:43 org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.26
14.7.2010 21:34:44 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
- Root WebApplicationContext: initialization started
- Refreshing org.springframework.web.context.support.XmlWebApplicationContext@2c
5444: display name [Root WebApplicationContext]
; startup date [Wed Jul 14 21:34:
44 EEST 2010]; root of context hierarchy
- Loaded 0 bean definitions from location pattern [classpath*:context.xml]
- Bean factory for application context [org.springframework.web.context.support.
XmlWebApplicationContext@2c5444]: org.springframework.beans.factory.support.Defa
ultListableBeanFactory@1e45e3
- 0 beans defined in org.springframework.web.context.support.XmlWebApplicationCo
ntext@2c5444: display name [Root WebApplicationContext]
; startup date [Wed Jul 1
4 21:34:44 EEST 2010]; root of context hierarchy
- Unable to locate MessageSource with name 'messageSource': using default [org.s
pringframework.context.support.DelegatingMessageSource@13c1b69]
- Unable to locate ApplicationEventMulticaster with name 'applicationEventMultic
aster': using default [org.springframework.context.event.SimpleApplicationEventM
ulticaster@1263b07]
- Unable to locate ThemeSource with name 'themeSource': using default [org.sprin
gframework.ui.context.support.ResourceBundleThemeSource@cf7fda]
- Pre-instantiating singletons in org.springframework.beans.factory.support.Defa
ultListableBeanFactory@1e45e3: defining beans []; root of factory hierarchy
- Published root WebApplicationContext as ServletContext attribute with name [or
g.springframework.web.context.WebApplicationContext.ROOT]
- Root WebApplicationContext: initialization completed in 172 ms
14.7.2010 21:34:44 org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
14.7.2010 21:34:44 org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
And when I start the application in browser it throws a null pointer exception from the FilerApplication class from that row where it first time uses the filerService.
It seems to me that my injection does not work so can someone tell me what I’m missing or have configured wrong??
Thanks in advance!!