Spring integration problem

Hi,

I am trying to configure vaadin to work with Spring via annotations, but even thought I have no error in log, the autowired property is null…
Here are all my files, where the problem could possible be…but i think, that I have configured it correctly…thanks for your help…

Pavel

----------------------------- META-INF/aop.xml










----------------------------- META-INF/context.xml



----------------------------- One of my context files, I want to autowire the categoryService bean
<context:annotation-config />
<context:component-scan base-package=“cz.micka.pavel.pamic.ui.panel” />
<context:load-time-weaver />
<aop:aspectj-autoproxy />

<bean name="categoryService" class="cz.micka.pavel.pamic.service.impl.CategoryService">
	<property name="dao" ref="categoryDAO" />
</bean>

----------------------------- Here is the problem…
package cz.micka.pavel.pamic.ui.panel;
.
.
.
@Configurable
public class PaMicPanel extends Panel {
@Autowired
private CategoryServiceIface categoryService;
public PaMicPanel() {
super();
createNewCategory();
contructCategoryTree();
}
.
.
.
private void contructCategoryTree() {
List roots = categoryService.getAllByParent(null); <------------ NULL pointer here
Tree t = new Tree();
for(Category root : roots){
constructNode(t, root);
}
this.addComponent(t);
}

----------------------------- LOG - everything seems OK to me
23.7.2009 19:02:28 org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]
{Server/Service/Engine/Host/Context} Setting property ‘source’ to ‘org.eclipse.jst.j2ee.server:PaMic’ did not find a matching property.
23.7.2009 19:02:28 org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]
{Server/Service/Engine/Host/Context/Loader} Setting property ‘useSystemClassLoaderAsParent’ to ‘false’ did not find a matching property.
23.7.2009 19:02:28 org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files (x86)\Java\jre6\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files (x86)/Java/jre6/bin/client;C:/Program Files (x86)/Java/jre6/bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;c:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;c:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn;c:\Program Files (x86)\Common Files\Roxio Shared\DLLShared;c:\Program Files (x86)\Common Files\Roxio Shared\DLLShared;c:\Program Files (x86)\Common Files\Roxio Shared\9.0\DLLShared;C:\Program Files (x86)\QuickTime\QTSystem;C:\Program Files (x86)\Samsung\Samsung PC Studio 3
23.7.2009 19:02:29 org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
23.7.2009 19:02:29 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1090 ms
23.7.2009 19:02:29 org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
23.7.2009 19:02:29 org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.20
23.7.2009 19:02:29 org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(C:\workspace\Java.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\PaMic\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
23.7.2009 19:02:30 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
19:02:30,248 INFO ContextLoader:189 - Root WebApplicationContext: initialization started
19:02:30,388 INFO XmlWebApplicationContext:411 - Refreshing org.springframework.web.context.support.XmlWebApplicationContext@b4faeb: display name [Root WebApplicationContext]
; startup date [Thu Jul 23 19:02:30 CEST 2009]
; root of context hierarchy
19:02:30,599 INFO XmlBeanDefinitionReader:323 - Loading XML bean definitions from ServletContext resource
[/WEB-INF/context/applicationContext.xml]
19:02:30,790 INFO XmlBeanDefinitionReader:323 - Loading XML bean definitions from ServletContext resource
[/WEB-INF/context/applicationContext-data.xml]
19:02:31,074 INFO XmlBeanDefinitionReader:323 - Loading XML bean definitions from ServletContext resource
[/WEB-INF/context/applicationContext-service.xml]
19:02:31,402 INFO XmlBeanDefinitionReader:323 - Loading XML bean definitions from ServletContext resource
[/WEB-INF/context/applicationContext-dao.xml]
19:02:31,423 INFO XmlWebApplicationContext:426 - Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@b4faeb]
: org.springframework.beans.factory.support.DefaultListableBeanFactory@139ed6d
19:02:31,827 INFO PropertyPlaceholderConfigurer:178 - Loading properties file from ServletContext resource
[/WEB-INF/properties/jdbc.properties]
19:02:31,830 INFO PropertyPlaceholderConfigurer:178 - Loading properties file from ServletContext resource
[/WEB-INF/properties/hibernate.properties]
19:02:31,859 INFO DefaultContextLoadTimeWeaver:78 - Using a reflective load-time weaver for class loader: org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader
19:02:35,225 INFO DefaultListableBeanFactory:414 - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@139ed6d: defining beans [propertyConfigurer,dataSource,hibernateTemplate,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,sessionFactory,transactionManager,transactionTemplate,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.weaving.AspectJWeavingEnabler#0,org.springframework.context.config.internalBeanConfigurerAspect,loadTimeWeaver,categoryService,categoryDAO]
; root of factory hierarchy
19:02:36,756 INFO DriverManagerDataSource:155 - Loaded JDBC driver: org.postgresql.Driver
23.7.2009 19:02:37 org.hibernate.cfg.Environment
INFO: Hibernate 3.3.0.SP1
23.7.2009 19:02:37 org.hibernate.cfg.Environment
INFO: hibernate.properties not found
23.7.2009 19:02:37 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : javassist
23.7.2009 19:02:37 org.hibernate.cfg.Environment
INFO: using JDK 1.4 java.sql.Timestamp handling
23.7.2009 19:02:38 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: cz.micka.pavel.pamic.bo.Category → Category
23.7.2009 19:02:39 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: cz.micka.pavel.pamic.bo.Category.subCategories → Category
19:02:39,455 INFO LocalSessionFactoryBean:730 - Building new Hibernate SessionFactory
23.7.2009 19:02:39 org.hibernate.connection.ConnectionProviderFactory newConnectionProvider
INFO: Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: PostgreSQL, version: 8.4.0
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.4 JDBC4 (build 701)
23.7.2009 19:02:40 org.hibernate.dialect.Dialect
INFO: Using dialect: org.hibernate.dialect.PostgreSQLDialect
23.7.2009 19:02:40 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
23.7.2009 19:02:40 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: on_close
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
23.7.2009 19:02:40 org.hibernate.hql.ast.ASTQueryTranslatorFactory
INFO: Using ASTQueryTranslatorFactory
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory createRegionFactory
INFO: Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
23.7.2009 19:02:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
23.7.2009 19:02:41 org.hibernate.impl.SessionFactoryImpl
INFO: building session factory
23.7.2009 19:02:42 org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
23.7.2009 19:02:42 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: Running hbm2ddl schema update
23.7.2009 19:02:42 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: fetching database metadata
23.7.2009 19:02:43 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: updating schema
23.7.2009 19:02:43 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: table found: public.category
23.7.2009 19:02:43 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: columns: [id, priority, name, parent]

23.7.2009 19:02:43 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: foreign keys: [fk6dd211ec4bead67]

23.7.2009 19:02:43 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: indexes: [category_pkey]

23.7.2009 19:02:43 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: schema update complete
19:02:44,040 INFO HibernateTransactionManager:421 - Using DataSource [org.springframework.jdbc.datasource.DriverManagerDataSource@1887b7]
of Hibernate SessionFactory for HibernateTransactionManager
19:02:44,302 INFO ContextLoader:209 - Root WebApplicationContext: initialization completed in 14047 ms
19:02:44,317 DEBUG OpenSessionInViewFilter:71 - Initializing filter…
23.7.2009 19:02:44 org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
23.7.2009 19:02:44 org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
23.7.2009 19:02:44 org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/161 config=null
23.7.2009 19:02:44 org.apache.catalina.startup.Catalina start
INFO: Server startup in 15631 ms

Vaadin is running in DEBUG MODE.
Add productionMode=true to web.xml to disable debug features.
To show debug window, add ?debug to your application URL.

com.vaadin.event.ListenerMethod$MethodException
Cause: java.lang.NullPointerException
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:507)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:158)
at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:980)
at com.vaadin.ui.Button.fireClick(Button.java:354)
at com.vaadin.ui.Button.changeVariables(Button.java:190)
at com.vaadin.terminal.gwt.server.CommunicationManager.handleVariables(CommunicationManager.java:716)
at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:285)
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:401)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at cz.micka.pavel.pamic.filter.OpenSessionInViewFilter.doFilter(OpenSessionInViewFilter.java:39)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at cz.micka.pavel.pamic.ui.panel.PaMicPanel.contructCategoryTree(PaMicPanel.java:56)
at cz.micka.pavel.pamic.ui.panel.PaMicPanel.(PaMicPanel.java:27)
at cz.micka.pavel.pamic.ui.panel.LoginPanel$1.buttonClick(LoginPanel.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:487)
… 23 more

Just to make sure - have you read http://vaadin.com/wiki/-/wiki/Main/Spring%20Integration ?

yes…and used google, and read several other articles…but no luck to get it working :slight_smile:

I have solved my problem…it was on different place, than i have expected…

The problem is, that I am using the autowired bean in constructor, beu default beahaviour is construct first, than inject…co the solusion is preConstruction=true in configurable annotation…

But as a noob, I have one suggestion for improvement in documentation…I think, that in the article about integration with spring should be link, or note about javaagents or instrumentableclassloaders…because on tomcat (and i think that noobs like me are using generally tomcat) you need to specify it for instrumentation of spring…but its only for your consideration…

Thanks

Pavel

Great to hear that you found the solution and thanks for reporting it back.

The article is a wiki-page written by the community. Could you add the proposed links to the page directly? Feel free to edit the article if you find anything that is outdated, incorrect or confusing. It’ll help the next Spring user to avoid problems.

Article updated. No need for load time weaver anymore as classes are compiled with aspectj compiler. If you are using Spring a lot you should check Spring Roo, because all the stuff is Spring specific. Vaadin itself has nothing to do with integration.

Thanks, I was preparing myself for doing it this afternoon :-).