Can you try adding line InjectorHolder.getInjector().inject(this);
on CustomAuthenticatedWebSession constructor? Ernesto On Thu, Nov 25, 2010 at 2:31 PM, Adam Gibbons <[email protected]> wrote: > Hi there, > I was wondering if anyone could help me with spring annotations, I seem to > have having some problems. > > I'm trying to inject my UserService into a CustomAuthenticatedWebSession I > wrote to do validation for my pages. > > I get a NPE when I hit any page because my bean does not seem to have been > injected. > > Here's my AuthenticatedWebSession Class: > > public class CustomAuthenticatedWebSession extends AuthenticatedWebSession{ > private static final long serialVersionUID = 4713195500103052768L; > > �...@springbean(name="userService") > transient private UserService userService; > public void setUserService(final UserService userService){ > this.userService = userService; > } > > transient private String currentUser = null; > > public CustomAuthenticatedWebSession(final Request request){ > super(request); > } > > �...@override > public boolean authenticate(final String username, final String > password){ > currentUser = username; > return userService.authenticate(username, password); > } > > �...@override > public Roles getRoles(){ > return userService.getRoles(currentUser, isSignedIn()); > } > } > > > my applicationContext.xml file: > > <?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:tx="http://www.springframework.org/schema/tx" > xmlns:context="http://www.springframework.org/schema/context" > xsi:schemaLocation=" > http://www.springframework.org/schema/beans > http://www.springframework.org/schema/beans/spring-beans-2.5.xsd > http://www.springframework.org/schema/aop > http://www.springframework.org/schema/aop/spring-aop-2.5.xsd > http://www.springframework.org/schema/tx > http://www.springframework.org/schema/tx/spring-tx-2.5.xsd > http://www.springframework.org/schema/context > http://www.springframework.org/schema/context/spring-context-2.5.xsd > " >> > <bean id="wicketApplication" > class="uk.co.company.product.presentation.wicket.app.WicketApplication" /> > > <bean id="placeholderConfigurer" > class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> > <property name="ignoreUnresolvablePlaceholders" value="false" /> > <property name="systemPropertiesModeName" > value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> > <property name="ignoreResourceNotFound" value="false" /> > <property name="locations"> > <list> > <value>classpath*:/application.properties</value> > </list> > </property> > </bean> > > <bean id="dataSource" > class="org.springframework.jdbc.datasource.DriverManagerDataSource"> > <property > name="driverClassName"><value>${jdbc.driver}</value></property> > <property name="url"><value>${jdbc.url}</value></property> > <property name="username"><value>${jdbc.username}</value></property> > <property name="password"><value>${jdbc.password}</value></property> > </bean> > > <tx:annotation-driven transaction-manager="txManager" /> > > <bean id="txManager" > > class="org.springframework.orm.hibernate3.HibernateTransactionManager"> > <property name="sessionFactory"> > <ref bean="sessionFactory" /> > </property> > </bean> > > <!-- > <bean id="interceptor" > class="org.springframework.orm.hibernate3.HibernateInterceptor"> > > </bean> > --> > > <bean id="sessionFactory" > class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> > <property name="dataSource" ref="dataSource" /> > <property name="hibernateProperties"> > <props> > <!-- <prop key="hibernate.hbm2ddl.auto">create</prop> --> > <prop key="hibernate.dialect">${hibernate.dialect}</prop> > <prop key="hibernate.connection.pool_size">5</prop> > <prop > key="hibernate.current_session_context_class">thread</prop> > <prop key="hibernate.show_sql">true</prop> > <prop > key="hibernate.cglib.use_reflection_optimizer">true</prop> > <prop > key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> > <prop > key="hibernate.hibernate.cache.use_query_cache">true</prop> > </props> > </property> > <!-- <property name="entityInterceptor"><ref bean="interceptor" > /></property> --> > <property name="packagesToScan"><list> > <value>uk.co.company.product.persistance.hibernate</value> > </list></property> > </bean> > <context:component-scan base-package="uk.co.company.product" /> > > </beans> > > > and web.xml > > <?xml version="1.0" encoding="UTF-8"?> > <web-app > xmlns="http://java.sun.com/xml/ns/j2ee" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation=" > http://java.sun.com/xml/ns/j2ee > http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd > " > version="2.4" >> > <display-name>ZenTemplate</display-name> > <context-param> > <param-name>contextConfigLocation</param-name> > <param-value>classpath:applicationContext.xml</param-value> > </context-param> > <listener> > > <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> > </listener> > <filter> > <filter-name>opensessioninview</filter-name> > > <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> > </filter> > <filter> > <filter-name>wicket-spring-hibernate</filter-name> > > <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class> > <init-param> > <param-name>applicationFactoryClassName</param-name> > > <param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value> > </init-param> > <init-param> > <param-name>applicationClassName</param-name> > > <param-value>uk.co.company.product.presentation.wicket.app.WicketApplication</param-value> > </init-param> > </filter> > <filter-mapping> > <filter-name>opensessioninview</filter-name> > <url-pattern>/*</url-pattern> > </filter-mapping> > <filter-mapping> > <filter-name>wicket-spring-hibernate</filter-name> > <url-pattern>/*</url-pattern> > </filter-mapping> > </web-app> > > Also here is my simple service: > > @Service("userService") > public class UserService{ > > final private TestUserService testUserService = new TestUserService(); > > public UserService(){ > super(); > } > > �...@transactional > final public boolean authenticate(final String userName, final String > password){ > return testUserService.authenticate(userName, password); > } > > �...@transactional > final public Roles getRoles(final String userName, final boolean > signedIn){ > return testUserService.getRoles(userName, signedIn); > } > } > > > If anyone has any ideas please let me know! > > Cheers, > Adam > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
