Hi,
First time here. Learning and Struggling. I have Struts2 web app with Spring for DI & Hibernate. It was working fine with Hibernate3 now want to make it work with Spring 3.1.2.RELEASE + Hibernate 4.1.7.
I have tried alot with different Maven dependencies for SPRING but no success. Below is error and my application configuration. Someone please help
MAVEN pom.xmlCode:SEVERE: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.config.internalAutoProxyCreator': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/core/convert/support/PropertyTypeDescriptor at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:965) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:710) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:410) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) Caused by: java.lang.NoClassDefFoundError: org/springframework/core/convert/support/PropertyTypeDescriptor at
accplicationContext.xmlCode:<properties> <java.version>1.6</java.version> <slf4j.version>1.6.6</slf4j.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <hibernate.core.version>4.1.7.Final</hibernate.core.version> <spring.version>3.1.2.RELEASE</spring.version> </properties> <dependencies> <!-- jUnit --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> </dependency> <!-- javaee-api 6 dependencies --> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>6.0</version> <scope>provided</scope> </dependency> <!-- struts2 dependencies --> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-core</artifactId> <version>2.3.4.1</version> </dependency> <!-- Struts 2 + Spring plugins --> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-spring-plugin</artifactId> <version>2.3.4.1</version> </dependency> <!-- JDBC dependencies --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.21</version> </dependency> <!-- Spring dependencies --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>${spring.version}</version> </dependency> <!-- Hibernate dependencies --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>${hibernate.core.version}</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>${hibernate.core.version}</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-c3p0</artifactId> <version>${hibernate.core.version}</version> </dependency> <!-- Spring AOP dependency --> <dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> <version>2.2.2</version> <scope>runtime</scope> </dependency> </dependencies>
Web.xmlCode:<?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:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <!--its core purpose is to bootstrap a SessionFactory from annotation scanning = LocalSessionFactoryBean.--> <!-- The singleton hibernate session factory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:hibernate.cfg.xml" /> </bean> <!-- defining transaction manager bean using Hibernate --> <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <!-- enable the configuration of transactional behavior based on annotations --> <tx:annotation-driven transaction-manager="txManager"/> <!-- Translates Hibernate exceptions to Spring Data Access Exceptions --> <bean class="org.springframework.orm.hibernate4.HibernateExceptionTranslator"/> <bean id="customerAction" class="com.mkyong.customer.action.CustomerAction"> <property name="customerBo" ref="customerBo" /> </bean> <bean id="customerBo" class="com.mkyong.customer.bo.impl.CustomerBoImpl" > <property name="customerDAO" ref="customerDAO" /> </bean> <!-- The singleton business services class, to be given to the actions --> <bean id="customerDAO" class="com.mkyong.customer.dao.impl.CustomerDAOImpl" > <property name="sessionFactory" ref="sessionFactory" /> </bean> </beans>
CustomerDAIImpl.javaCode:<!-- Spring --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <listener> <!-- Required for the struts2 spring plugin to work --> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <filter> <!-- Get spring to keep the session open for the whole request, so hibernate's lazy loads work --> <filter-name>openSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>openSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
Code:package com.mkyong.customer.dao.impl; import com.mkyong.customer.dao.CustomerDAO; import com.mkyong.customer.model.Customer; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.springframework.transaction.annotation.Transactional; import java.util.List; @Transactional public class CustomerDAOImpl implements CustomerDAO{ protected SessionFactory sessionFactory; public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } // Shortcut for sessionFactory.getCurrentSession() protected Session session() { return sessionFactory.getCurrentSession(); } //add the customer public void addCustomer(Customer customer){ session().saveOrUpdate(customer); } //return all the customers in list @Transactional(readOnly = true) public List<Customer> listCustomer(){ return session().createQuery("from Customer").list(); } }


Reply With Quote
ackagesToScan. Should I use it in my situation. Without it code is working?
. For what it does I suggest a read of the reference guide which explains bean scopes..
