Hi James, Thanks for the suggestion! However, even with your change, I still get the "There is no application attached to current thread ContainerBackgroundProcessor[StandardEngine[Catalina]]" error.
Regards, Adam On 15 December 2010 11:17, James Carman [via Apache Wicket] < ml-node+3088802-1498820770-201...@n4.nabble.com<ml-node%2b3088802-1498820770-201...@n4.nabble.com> > wrote: > @SpringBean isn't for use inside your Spring services, just Wicket > stuff. Just use the native Spring injection mechanisms. Try > @Autowired. > > On Wed, Dec 15, 2010 at 5:43 AM, Adam Gibbons <[hidden > email]<http://user/SendEmail.jtp?type=node&node=3088802&i=0>> > wrote: > > > Hi there, > > > > For some time now I have been trying to put together a simple project to > get > > me off the ground with a Wicket/Spring/Hibernate setup. I've had lots of > ups > > and downs, and found this guide really useful: > > http://wicketinaction.com/2009/06/wicketspringhibernate-configuration/ > > However, I still seem to be having some problems and I've no idea where > to > > look now. > > > > Here's the error I get in my log: > > > > org.springframework.beans.factory.BeanCreationException: Error creating > bean > > with name 'userServiceImpl' defined in file > > > [C:\tomcat6\webapps\ZenTemplate-0\WEB-INF\classes\uk\co\company\product\business\spring\UserServiceImpl.class]: > > > Instantiation of bean failed; nested exception is > > org.springframework.beans.BeanInstantiationException: Could not > instantiate > > bean class [uk.co.company.product.business.spring.UserServiceImpl]: > > Constructor threw exception; nested exception is org.apache.wicket.Wicket > > > RuntimeException: There is no application attached to current thread > > ContainerBackgroundProcessor[StandardEngine[Catalina]] > > at > > > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:883) > > > at > > > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:839) > > > at > > > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440) > > > at > > > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) > > > at java.security.AccessController.doPrivileged(Native Method) > > at > > > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) > > > at > > > org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) > > > at > > > org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) > > > at > > > org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) > > > at > > > org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) > > > at > > > org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) > > > at > > > org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429) > > > at > > > org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728) > > > at > > > org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380) > > > at > > > org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255) > > > at > > > org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199) > > > at > > > org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45) > > > at > > > org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135) > > > at > > org.apache.catalina.core.StandardContext.start(StandardContext.java:4630) > > > at > > > org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791) > > > at > > org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771) > > at > > org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546) > > at > > org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:905) > > at > > org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:740) > > at > > org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:500) > > at > > org.apache.catalina.startup.HostConfig.check(HostConfig.java:1345) > > at > > > org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:303) > > at > > > org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) > > > at > > > org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1337) > > > at > > > org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601) > > > at > > > org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610) > > > at > > > org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590) > > > at java.lang.Thread.run(Thread.java:619) > > Caused by: org.springframework.beans.BeanInstantiationException: Could > not > > instantiate bean class > > [uk.co.company.product.business.spring.UserServiceImpl]: Constructor > threw > > exception; nested exception is org.apache.wicket.WicketRuntimeException: > > There is no application attached to current thread > > ContainerBackgroundProcessor[StandardEngine[Catalina]] > > at > > org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:115) > > at > > > org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:61) > > > at > > > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:877) > > > ... 32 more > > Caused by: org.apache.wicket.WicketRuntimeException: There is no > application > > attached to current thread > > ContainerBackgroundProcessor[StandardEngine[Catalina]] > > at org.apache.wicket.Application.get(Application.java:181) > > at > > > org.apache.wicket.injection.web.InjectorHolder.getInjector(InjectorHolder.java:67) > > > at > > > uk.co.company.product.business.spring.UserServiceImpl.<init>(UserServiceImpl.java:35) > > > at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native > > Method) > > at > > > sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) > > > at > > > sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) > > > at java.lang.reflect.Constructor.newInstance(Constructor.java:513) > > > at > > org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100) > > ... 34 more > > 15-Dec-2010 10:33:44 org.apache.catalina.core.StandardContext start > > SEVERE: Error listenerStart > > 15-Dec-2010 10:33:44 org.apache.catalina.core.StandardContext start > > SEVERE: Context [/ZenTemplate-0] startup failed due to previous errors > > 15-Dec-2010 10:33:44 org.apache.catalina.loader.WebappClassLoader > > clearReferencesJdbc > > SEVERE: The web application [/ZenTemplate-0] registered the JBDC driver > > [com.mysql.jdbc.Driver] but failed to unregister it when the web > application > > was stopped. To prevent a memory leak, the JDBC Driver has been forcibly > > unregistered. > > 15-Dec-2010 10:33:44 org.apache.catalina.loader.WebappClassLoader > > clearReferencesThreads > > SEVERE: The web application [/ZenTemplate-0] appears to have started a > > thread named [MySQL Statement Cancellation Timer] but has failed to stop > it. > > This is very likely to create a memory leak. > > > > 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> > > > > applicationContext.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: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 > > " > > default-autowire-candidates="*Service,*DAO,*Bean" > > default-autowire="byType" > > default-lazy-init="false" > >> > > <!-- <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="sessionFactory" /> > > </bean> > > > > <!--<bean id="interceptor" > > class="com.mycompany.hibernate.HibernateInterceptor"> > > </bean>--> > > > > <bean id="sessionFactory" > > > class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> > > > <property name="dataSource" ref="dataSource" /> > > <property name="hibernateProperties"> > > <props> > > <!-- GENERAL --> > > <prop key="hibernate.dialect">${hibernate.dialect}</prop> > > <prop key="hibernate.show_sql">true</prop> > > <prop key="hibernate.show_sql">hibernate.format_sql</prop> > > > <prop key="hibernate.default_schema">zen_template</prop> > > <prop key="hibernate.max_fetch_depth">2</prop> > > <!-- <prop > > key="hibernate.default_batch_fetch_size">16</prop> --> > > <prop key="hibernate.default_entity_mode">pojo</prop> > > <prop key="hibernate.order_updates">true</prop> > > <prop key="hibernate.generate_statistics">true</prop> > > <prop key="hibernate.use_identifier_rollback">true</prop> > > <prop > > key="hibernate.current_session_context_class">thread</prop> > > <prop key="hibernate.use_outer_join">true</prop> > > <!-- JDBC --> > > <!-- <prop key="hibernate.jdbc.batch_size">20</prop> --> > > <!-- <prop > > key="hibernate.jdbc.batch_versioned_data">true</prop> --> > > <prop > > key="hibernate.jdbc.use_streams_for_binary">true</prop> > > <prop > > key="hibernate.jdbc.use_get_generated_keys">true</prop> > > <!-- CONNECTION --> > > <prop key="hibernate.connection.isolation">8</prop><!-- > > TRANSACTION_SERIALIZABLE --> > > <prop key="hibernate.connection.autocommit">false</prop> > > <prop key="hibernate.connection.pool_size">5</prop> > > <!-- CACHE --> > > <!-- <prop > > > key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> > > > --> > > <!-- <prop > > key="hibernate.cache.use_minimal_puts">true</prop> --> > > <!-- <prop > key="hibernate.cache.use_query_cache">true</prop> > > --> > > <!-- MISCELLANEOUS --> > > <prop > > key="hibernate.bytecode.use_reflection_optimizer">true</prop> > > <prop > > key="hibernate.cglib.use_reflection_optimizer">true</prop> > > <!-- <prop key="hibernate.bytecode.provider">cglib</prop> > > --> > > <!-- <prop key="hibernate.query.substitutions">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> > > > > my WicketApplication.java: > > > > public class WicketApplication extends AuthenticatedWebApplication{ > > > > public WicketApplication(){ > > super(); > > } > > > > @Override > > final public Class<HomePage> getHomePage(){ > > return HomePage.class; > > } > > > > @Override > > final protected Class<? extends WebPage> getSignInPageClass(){ > > return LoginPage.class; > > } > > > > @Override > > final protected Class<? extends AuthenticatedWebSession> > > getWebSessionClass() { > > return CustomAuthenticatedWebSession.class; > > } > > > > @Override > > final protected void init(){ > > super.init(); > > addComponentInstantiationListener(new > > SpringComponentInjector(this)); > > final IApplicationSettings appSettings = getApplicationSettings(); > > > appSettings.setAccessDeniedPage(CustomAccessDeniedPage.class); > > //appSettings.setPageExpiredErrorPage(null); > > //appSettings.setInternalErrorPage(null); > > } > > } > > > > my CustomAuthenticatedWebSession: > > > > public class CustomAuthenticatedWebSession extends > AuthenticatedWebSession{ > > private static final long serialVersionUID = 4713195500103052768L; > > > > @SpringBean > > private UserService userService; > > public void setUserService(final UserService userService){ > > this.userService = userService; > > } > > > > transient private String currentUser = null; > > > > public CustomAuthenticatedWebSession(final Request request){ > > super(request); > > InjectorHolder.getInjector().inject(this);//<-- VERY IMPORTANT to > > get Spring DI to work. > > } > > > > @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 UserServiceImpl.java: > > > > @Service > > public class UserServiceImpl extends _AbstractService implements > > UserService{ > > > > final private TestUserService testUserService = new TestUserService(); > > > > > @SpringBean > > private Temp1DAO temp1DAO; > > /* (non-Javadoc) > > * @see > > > uk.co.company.product.business.spring.UserService#setTemp1DAO(uk.co.company.product.persistance.hibernate.Temp1DAO) > > > */ > > @Override > > @Required > > final public void setTemp1DAO(final Temp1DAO temp1dao){ > > temp1DAO = temp1dao; > > } > > > > public UserServiceImpl(){ > > super(); > > InjectorHolder.getInjector().inject(this);//<-- VERY IMPORTANT to > > get Spring DI to work. > > } > > > > /* (non-Javadoc) > > * @see > > > uk.co.company.product.business.spring.UserService#authenticate(java.lang.String, > > > java.lang.String) > > */ > > @Override > > @Transactional > > final public boolean authenticate(final String userName, final String > > password){ > > final Temp1 temp1 = new Temp1(); > > temp1.setValue(userName); > > temp1DAO.save(temp1); > > return testUserService.authenticate(userName, password); > > } > > > > /* (non-Javadoc) > > * @see > > > uk.co.company.product.business.spring.UserService#getRoles(java.lang.String, > > > boolean) > > */ > > @Override > > @Transactional > > final public Roles getRoles(final String userName, final boolean > > signedIn){ > > return testUserService.getRoles(userName, signedIn); > > } > > } > > > > and finally Temp1DAOImpl.java: > > > > @Repository > > public class Temp1DAOImpl extends AbstractTemp1DAO implements Temp1DAO{ > > private static final Log log = LogFactory.getLog(Temp1DAOImpl.class); > > > > public Temp1DAOImpl(){ > > super(); > > log.debug("Temp1DAO created."); > > } > > } > > > > I did have this working to the point where it would start up without > errors, > > although it would die when trying to call userServiceImpl.authenticate() > due > > to a NPE for temp1DAO. (It seemed odd before that it would do DI for > > Services but not for DAOs...) > > I'm sure I'm missing something blindingly obvious, but I'd really > appriciate > > a second opinion. > > > > Thanks in advance for all help and assistance!! > > > > > > Cheers, > > Adam > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden > email]<http://user/SendEmail.jtp?type=node&node=3088802&i=1> > For additional commands, e-mail: [hidden > email]<http://user/SendEmail.jtp?type=node&node=3088802&i=2> > > > > ------------------------------ > View message @ > http://apache-wicket.1842946.n4.nabble.com/help-me-please-Wicket-Spring-Hibernate-configuration-woes-tp3088768p3088802.html > > To start a new topic under Apache Wicket, email > ml-node+1842946-1499480286-201...@n4.nabble.com<ml-node%2b1842946-1499480286-201...@n4.nabble.com> > 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/help-me-please-Wicket-Spring-Hibernate-configuration-woes-tp3088768p3089024.html Sent from the Users forum mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org