2 wfsgwk wfsgwk 于 2015.06.05 23:41 提问

myexclipse的ssh整合的问题,运行就出错 5C

错误问题:
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.hibernate.cfg.Configuration]: Constructor threw exception; nested exception is java.lang.NoSuchFieldError: INSTANCE
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1403)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:545)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:245)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:188)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4334)
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:525)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.hibernate.cfg.Configuration]: Constructor threw exception; nested exception is java.lang.NoSuchFieldError: INSTANCE
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:104)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newConfiguration(LocalSessionFactoryBean.java:779)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:561)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:134)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1460)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1400)
... 36 more
Caused by: java.lang.NoSuchFieldError: INSTANCE
at org.hibernate.type.BasicTypeRegistry.(BasicTypeRegistry.java:94)
at org.hibernate.type.TypeResolver.(TypeResolver.java:59)
at org.hibernate.cfg.Configuration.(Configuration.java:250)
at org.hibernate.cfg.Configuration.(Configuration.java:302)
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:126)
... 42 more
2015-6-5 23:13:14 org.apache.catalina.core.StandardContext start
严重: Error listenerStart
2015-6-5 23:13:14 org.apache.catalina.core.StandardContext start
严重: Context [/xslg] startup failed due to previous errors
2015-6-5 23:13:14 org.apache.catalina.core.ApplicationContext log

我的applicationContext.xml如下
<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName"
        value="com.mysql.jdbc.Driver">
    </property>
    <property name="url" value="jdbc:mysql://localhost:3306/wk1"></property>
    <property name="username" value="root"></property>
    <property name="password" value="123456"></property>
</bean>
<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
        <ref bean="dataSource" ></ref>
    </property>
    <property name="configLocation"> 

WEB-INF/classes/hibernate.cfg.xml




org.hibernate.dialect.MySQLDialect

update




com/po/User.hbm.xml
















5个回答

cuiwei1026522829
cuiwei1026522829   Ds   Rxr 2015.06.05 23:53

Error creating bean with name 'sessionFactory' defined in ServletContext resource
session创建有问题

Caused by: java.lang.NoSuchFieldError: INSTANCE

你看这句,实例有问题,你好好看看你的映射文件!!!有问题呼叫我

wfsgwk
wfsgwk 映射文件应用的时Hibernate反定义,没有问题。
2 年多之前 回复
wfsgwk
wfsgwk 映射文件应用的时Hibernate反定义,没有问题。
2 年多之前 回复
guwei4037
guwei4037   Ds   Rxr 2015.06.06 06:38
angeldwind
angeldwind   2015.06.07 13:30

解决办法是:
1.去掉类路径上的关于Hibernate的3个lib
asm.jar
asm-attrs.jar
cglib-2.1.3.jar
2.加入Spring中的以下4个lib
asm-2.2.2.jar
asm-commons-2.2.2.jar
asm-util-2.2.2.jar
cglib-nodep-2.1_3.jar

另一种解决方法
去掉Spring中的asm-2.2.2.jar
hibernate-myexclipse的ssh整合的问题,运行就出错-CSDN问答

SuperStonne
SuperStonne   2015.06.07 19:15

如果你是为了加载spring mvc的配置文件而在web.xml中配置了listener,那么请注意如下:
使用的web容器支持servlet 2.3 或者更高版本的,你可以在web.xml 配置


 <listener>
<listener-class>org.springframework.
web.context.ContextLoaderListener</listener-class>
</listener>

使用的web容器支持servlet2.2 或者较低版本的或者支持2.3,但是在初始化servlet之前并没有初始化listener,你可以在web.xml中配置

 <servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.
web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

希望对你有用

javai18n
javai18n   2015.06.12 16:36

Spring的监听配置有问题,检查下你的web.xml文件。
如果你是springmvc并且配置文件叫spring-servlet.xml并且在WEB-INF下
可以不用写监听
直接配置

 <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>0</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>
Csdn user default icon
上传中...
上传图片
插入图片