6
回答
spring3+hibernate4 java.lang.NoSuchMethodException: org.springframework.orm.hibernate4.SpringSessionContext.<init>()
滴滴云服务器,限时包月0.9元,为开发者而生>>>   

错误信息:

java.lang.NoSuchMethodException: org.springframework.orm.hibernate4.SpringSessionContext.<init>() org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.springframework.orm.hibernate4.SpringSessionContext lovemie.com.controller.UserController.ssc; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateTemplate' defined in ServletContext resource [/WEB-INF/applicationContext-common.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate4.SpringSessionContext]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.springframework.orm.hibernate4.SpringSessionContext.<init>()


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:mvc="http://www.springframework.org/schema/mvc" 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"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context.xsd
      http://www.springframework.org/schema/mvc
      http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
      http://www.springframework.org/schema/tx
	  http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
	  http://www.springframework.org/schema/aop         
      http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
      http://www.springframework.org/schema/jee
      http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
      http://www.springframework.org/schema/jdbc
      http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd">


	<context:annotation-config />


	<!-- 启动注解驱动的Spring MVC功能,注册请求url和注解POJO类方法的映射 -->
	<mvc:annotation-driven />
	<!-- 启动包扫描功能,以便注册带有@Controller、@Service、@repository、@Component等注解的类成为spring的bean -->
	<!-- 
	<context:component-scan base-package="lovemie.com.controller" />
	 -->
	<context:component-scan base-package="lovemie.com" />
	<!-- 对模型视图名称的解析,在请求时模型视图名称添加前后缀 -->
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/view/" p:suffix=".jsp" />




	<!-- 引入配置文件 -->
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations"> 
            <list> 
                <value>/WEB-INF/jdbc.properties</value> 
            </list> 
        </property> 
    </bean>

	<!-- 数据源连接池 -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
		<property name="driverClassName" value="org.gjt.mm.mysql.Driver">
		</property>
		<property name="url" value="jdbc:mysql://localhost:3306/lovemie"></property>
		<property name="username" value="root"></property>
		<property name="password" value="root"></property>
	</bean>

	<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
		<!-- 
			<property name="configLocation" value="classpath:hibernate.cfg.xml">
			<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />
			<property name="configLocations" value="hibernate.model.xml" />
			-->
		<property name="dataSource">
			<ref local="dataSource" />
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
				<prop key="hibernate.show_sql">true</prop>
				<prop key="hibernate.hbm2ddl.auto">update</prop>
			</props>
		</property>
		<property name="current_session_context_class" value="thread" />
		<property name="configLocation" value="/WEB-INF/hibernate.cfg.xml"></property>
		<property name="mappingResources">  
            <list>
            	<!--  
                <value>com/neusoft/leehom/model/Emp.hbm.xml</value>
                <value>com/neusoft/leehom/model/Dept.hbm.xml</value>
            	-->
            </list>
        </property>
	</bean>
	<!-- 
		<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> -->
	<bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.SpringSessionContext">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>

	<!-- 配置事务管理器 -->
	<bean id="transactionManager"
		class="org.springframework.orm.hibernate4.HibernateTransactionManager">
		<property name="sessionFactory">
			<ref bean="sessionFactory" />
		</property>
	</bean>
	<!-- 配置事务的传播特性 -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="insert*" propagation="REQUIRED" />
			<tx:method name="add*" propagation="REQUIRED" />
			<tx:method name="save*" propagation="REQUIRED" />
			<tx:method name="delete*" propagation="REQUIRED" />
			<tx:method name="update*" propagation="REQUIRED" />
			<tx:method name="get*" propagation="REQUIRED" read-only="true"/>  
            <tx:method name="query*" propagation="REQUIRED" read-only="true"/>
			<tx:method name="*" read-only="true" />
		</tx:attributes>
	</tx:advice>
	<!-- 方法参与事务 -->
	<aop:config>
		<aop:pointcut id="allManagerMethod" expression="execution(* lovemie.com.service.*.*(..))" />
		<aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice" />
	</aop:config>
	<!-- 
		需要引入aop的命名空间
	    <aop:config>
	                切入点指明了在执行Service的所有方法时产生事务拦截操作
	        <aop:pointcut id="daoMethods" expression="execution(* com.neusoft.leehom.service.impl.*.*(..))" />
	                定义了将采用何种拦截操作,这里引用到 txAdvice
	        <aop:advisor advice-ref="txAdvice" pointcut-ref="daoMethods" />
	    </aop:config>
    -->

	<!-- spring jdbc -->
	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
		<property name="dataSource" ref="dataSource" />
	</bean>
	
	
</beans>


maven / pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

	<modelVersion>4.0.0</modelVersion>
	<groupId>lovemie.com</groupId>
	<artifactId>webapp</artifactId>
	<packaging>war</packaging>
	<version>0.0.1-SNAPSHOT</version>
	<name>webapp Maven Webapp</name>
	<url>http://maven.apache.org</url>

	<repositories>
		<repository>
			<id>java.net</id>
			<url>http://download.java.net/maven/2/</url>
		</repository>
	</repositories>

	<properties>
		<hibernate.version>4.2.2</hibernate.version>
	</properties>
  
  <dependencies>
	<dependency>
		<groupId>junit</groupId>
		<artifactId>junit</artifactId>
		<version>4.11</version>
	</dependency>
            
    
    <!-- spring -->
	<dependency>
		<groupId>org.springframework.data</groupId>
		<artifactId>spring-data-commons-core</artifactId>
		<version>1.4.1.RELEASE</version>
	</dependency>
	<dependency>
		<groupId>org.springframework.osgi</groupId>
		<artifactId>spring-osgi-annotation</artifactId>
		<version>1.2.1</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-webmvc</artifactId>
		<version>3.2.2.RELEASE</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-beans</artifactId>
		<version>3.2.2.RELEASE</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-core</artifactId>
		<version>3.2.2.RELEASE</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-context</artifactId>
		<version>3.2.2.RELEASE</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-dao</artifactId>
		<version>2.0.8</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-jdbc</artifactId>
		<version>3.2.2.RELEASE</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-tx</artifactId>
		<version>3.2.2.RELEASE</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-orm</artifactId>
		<version>3.1.1.RELEASE</version>
		<!-- will come with all needed Spring dependencies such as spring-core and spring-beans -->
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-expression</artifactId>
		<version>3.2.2.RELEASE</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-context-support</artifactId>
		<version>3.2.2.RELEASE</version>
	</dependency>
            
            
            
	<!-- Hibernate -->
	<dependency>
		<groupId>org.hibernate</groupId>
		<artifactId>hibernate-core</artifactId>
		<version>4.2.0.Final</version>
	</dependency>
	<dependency>
		<groupId>org.hibernate</groupId>
		<artifactId>hibernate-entitymanager</artifactId>
		<version>4.2.1.Final</version>
	</dependency>
	<dependency>
		<groupId>org.hibernate</groupId>
		<artifactId>hibernate-validator</artifactId>
		<version>5.0.1.Final</version>
	</dependency>
	<dependency>
		<groupId>org.hibernate</groupId>
		<artifactId>hibernate-ehcache</artifactId>
		<version>4.2.1.Final</version>
	</dependency>
	<dependency>
		<groupId>org.hibernate</groupId>
		<artifactId>hibernate-entitymanager</artifactId>
		<version>4.1.1.Final</version>
		<!-- will come with Hibernate core -->
	</dependency>
<!--
	<dependency>
		<groupId>org.hibernate</groupId>
		<artifactId>hibernate-commons-annotations</artifactId>
		<version>3.3.0.ga</version>
	</dependency>
 -->
	<dependency>
		<groupId>org.hibernate.javax.persistence</groupId>
		<artifactId>hibernate-jpa-2.0-api</artifactId>
		<version>1.0.1.Final</version>
	</dependency>
            
            
    <!-- mysql driver -->
	<dependency>
		<groupId>mysql</groupId>
		<artifactId>mysql-connector-java</artifactId>
		<version>5.1.25</version>
	</dependency>
	<!-- jetty plugin -->
	<!-- other -->
	<dependency>
		<groupId>commons-dbcp</groupId>
		<artifactId>commons-dbcp</artifactId>
		<version>1.4</version>
	</dependency>
	<dependency>
		<groupId>org.slf4j</groupId>
		<artifactId>slf4j-api</artifactId>
		<version>1.7.5</version>
	</dependency>
	<dependency>
		<groupId>org.slf4j</groupId>
		<artifactId>slf4j-log4j12</artifactId>
		<version>1.7.5</version>
	</dependency>
	<dependency>
		<groupId>log4j</groupId>
		<artifactId>log4j</artifactId>
		<version>1.2.17</version>
	</dependency>
	<dependency>
		<groupId>cglib</groupId>
		<artifactId>cglib</artifactId>
		<version>2.2.2</version>
		<scope>runtime</scope>
	</dependency>
	<dependency>
		<groupId>org.aspectj</groupId>
		<artifactId>aspectjweaver</artifactId>
		<version>1.7.2</version>
	</dependency>
	<dependency>
		<groupId>commons-collections</groupId>
		<artifactId>commons-collections</artifactId>
		<version>3.2.1</version>
	</dependency>
	<dependency>
		<groupId>org.apache.geronimo.bundles</groupId>
		<artifactId>aspectjrt</artifactId>
		<version>1.6.8_2</version>
	</dependency>
	<dependency>
		<groupId>aopalliance</groupId>
		<artifactId>aopalliance</artifactId>
		<version>1.0</version>
	</dependency>
	            
            



  </dependencies>
  <build>
    <finalName>webapp</finalName>
  </build>
</project>


搞了N 久, 百度了两天的 google 都没找到解决办法 。  求解 。

举报
sjack
发帖于5年前 6回/5K+阅
顶部