ERROR org.springframework.web.context.ContextLoader:224 - Context initialization
java.lang.NoClassDefFoundError: org/hibernate/MappingException
Caused by: java.lang.ClassNotFoundException: org.hibernate.MappingException
Struts2.1+Spring3.0+hibernate3.3 。配完spring+ hibernate 后一切正常。但是加入STRUTS 后,一起动TOMCAT 就报以上异常,
但是单独用junit测试 方法仍能允许。
applicationContext.xml
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
<property name="packagesToScan">
<list>
<value>com.hit.model</value>
</list>
</property>
</bean>
<context:annotation-config/>
<context:component-scan base-package="com.hit"/>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="fooServiceOperation"
expression="execution(public * com.hit.service..*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="fooServiceOperation"/>
</aop:config>
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<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>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping></web-app>
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.objectFactory" value="spring"></constant>
<package name="admin" extends="struts-default" >
<action name="admin" class="com.hit.adcion.AdminAction" method="login">
<result>/index.jsp</result>
</action>
</package>
</struts>
package com.hit.adcion;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import com.hit.service.AdminService;
import com.opensymphony.xwork2.ActionSupport;
@Component
public class AdminAction extends ActionSupport{
private AdminService adminService;
private String name;
private String password;
public String login()
{
return SUCCESS;
}
public AdminService getAdminService() {
return adminService;
}
public String getName() {
return name;
}
public String getPassword() {
return password;
}
@Resource(name ="adminService")
public void setAdminService(AdminService adminService) {
this.adminService = adminService;
}
public void setName(String name) {
this.name = name;
}
public void setPassword(String password) {
this.password = password;
}