I guess if the Application is a singleton I could use it as a ServiceLocator. Might be better than injecting the bean over and over again in CustomAuthenticatedWebSession. Most of the wicket objects seem to have a getApplication method so it might be a nice way of handling my services for future wicket development.
On 25 November 2010 13:48, Ernesto Reinaldo Barreiro-4 [via Apache Wicket] < [email protected]<ml-node%[email protected]> > wrote: > The explanation is that Wicket injection magic only works for > components: at other places you have to call the magic yourself:-) > > Ernesto > > P.S. Would it make sense to put you service at application level and > make session fetch it from there? > > On Thu, Nov 25, 2010 at 2:39 PM, adam.gibbons <[hidden > email]<http://user/SendEmail.jtp?type=node&node=3058965&i=0>> > wrote: > > > > > It worked!! Thank you sooo much!! \(^_^)/ > > > > On 25 November 2010 13:36, Ernesto Reinaldo Barreiro-4 [via Apache > Wicket] < > > [hidden email] > > <http://user/SendEmail.jtp?type=node&node=3058965&i=1><[hidden > email] <http://user/SendEmail.jtp?type=node&node=3058965&i=2>> > >> wrote: > > > >> Can you try adding line > >> > >> InjectorHolder.getInjector().inject(this); > >> > >> on CustomAuthenticatedWebSession constructor? > >> > >> Ernesto > >> > >> On Thu, Nov 25, 2010 at 2:31 PM, Adam Gibbons <[hidden email]< > http://user/SendEmail.jtp?type=node&node=3058948&i=0>> > >> 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: [hidden email]< > http://user/SendEmail.jtp?type=node&node=3058948&i=1> > >> For additional commands, e-mail: [hidden email]< > http://user/SendEmail.jtp?type=node&node=3058948&i=2> > >> > >> > >> > >> ------------------------------ > >> View message @ > >> > http://apache-wicket.1842946.n4.nabble.com/need-help-with-spring-annotations-tp3058944p3058948.html<http://apache-wicket.1842946.n4.nabble.com/need-help-with-spring-annotations-tp3058944p3058948.html?by-user=t> > >> > >> To start a new topic under Apache Wicket, email > >> [hidden email] > >> <http://user/SendEmail.jtp?type=node&node=3058965&i=3><[hidden > email] <http://user/SendEmail.jtp?type=node&node=3058965&i=4>> > >> To unsubscribe from Apache Wicket, click here< > http://apache-wicket.1842946.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=1842946&code=YWRhbS5zLmdpYmJvbnNAZ21haWwuY29tfDE4NDI5NDZ8LTUzNzMyMDU4OQ==<http://apache-wicket.1842946.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=1842946&code=YWRhbS5zLmdpYmJvbnNAZ21haWwuY29tfDE4NDI5NDZ8LTUzNzMyMDU4OQ==&by-user=t>>. > > >> > >> > > > > -- > > View this message in context: > http://apache-wicket.1842946.n4.nabble.com/need-help-with-spring-annotations-tp3058944p3058950.html<http://apache-wicket.1842946.n4.nabble.com/need-help-with-spring-annotations-tp3058944p3058950.html?by-user=t> > > Sent from the Users forum mailing list archive at Nabble.com. > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [hidden > > email]<http://user/SendEmail.jtp?type=node&node=3058965&i=5> > > For additional commands, e-mail: [hidden > > email]<http://user/SendEmail.jtp?type=node&node=3058965&i=6> > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden > email]<http://user/SendEmail.jtp?type=node&node=3058965&i=7> > For additional commands, e-mail: [hidden > email]<http://user/SendEmail.jtp?type=node&node=3058965&i=8> > > > > ------------------------------ > View message @ > http://apache-wicket.1842946.n4.nabble.com/need-help-with-spring-annotations-tp3058944p3058965.html > > To start a new topic under Apache Wicket, email > [email protected]<ml-node%[email protected]> > To unsubscribe from Apache Wicket, click > here<http://apache-wicket.1842946.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=1842946&code=YWRhbS5zLmdpYmJvbnNAZ21haWwuY29tfDE4NDI5NDZ8LTUzNzMyMDU4OQ==>. > > -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/need-help-with-spring-annotations-tp3058944p3058977.html Sent from the Users forum mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
