mvn jetty期间出现Spring + Hiber错误:运行

时间:2012-10-04 07:22:20

标签: spring hibernate jetty

运行后:mvn jetty:运行


HTTP错误:503

访问/ ContactManager时出现问题。原因是:

Service Unavailable

由Jetty提供://

日志文件中的

- 错误:

错误:org.springframework.web.context.ContextLoader - 上下文初始化失败 org.springframework.beans.factory.BeanCreationException:创建名称为' contactDAOImpl'的注册自动连接依赖项失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配字段:private org.hibernate.SessionFactory org.taranov.contactmanager.dao.ContactDAOImpl.sessionFactory;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为' sessionFactory'的bean时出错在ServletContext资源[/WEB-INF/spring/data.xml]中定义:init方法的调用失败;嵌套异常是org.hibernate.service.spi.ServiceException:无法创建请求的服务[org.hibernate.service.jdbc.connections.spi.ConnectionProvider]         在org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)         在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)         在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)         在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)         在org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:294)         在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)         在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)         在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)         at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)         在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)         在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)         at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384)         在org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)         在org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)         at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:771)         at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:411)         at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:763)         at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:247)         at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1238)         at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:706)         at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:480)         在org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:293)         at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)         在org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)         at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:172)         at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)         在org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)         at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)         在org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)         在org.eclipse.jetty.server.Server.doStart(Server.java:277)         在org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:65)         at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)         在org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:511)         在org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:364)         在org.mortbay.jetty.plugin.JettyRunMojo.execute(JettyRunMojo.java:516)         在org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)         在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)         在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)         在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)         在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)         在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)         在org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)         在org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)         在org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)         在org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)         在org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)         在org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)         在org.apache.maven.cli.MavenCli.main(MavenCli.java:141)         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)         在java.lang.reflect.Method.invoke(Method.java:601)         在org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)         在org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)         在org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)         在org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)     引起:org.springframework.beans.factory.BeanCreationException:无法自动装配字段:private org.hibernate.SessionFactory org.taranov.contactmanager.dao.ContactDAOImpl.sessionFactory;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为' sessionFactory'的bean时出错在ServletContext资源[/WEB-INF/spring/data.xml]中定义:init方法的调用失败;嵌套异常是org.hibernate.service.spi.ServiceException:无法创建请求的服务[org.hibernate.service.jdbc.connections.spi.ConnectionProvider]         at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506)         在org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)         at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)         ......还有55个     引起:org.springframework.beans.factory.BeanCreationException:创建名称为' sessionFactory'的bean时出错在ServletContext资源[/WEB-INF/spring/data.xml]中定义:init方法的调用失败;嵌套异常是org.hibernate.service.spi.ServiceException:无法创建请求的服务[org.hibernate.service.jdbc.connections.spi.ConnectionProvider]         在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)         在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)         在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)         在org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:294)         在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)         在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)         在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)         at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:848)         在org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:790)         在org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)         在org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)         ......还有57个     引起:org.hibernate.service.spi.ServiceException:无法创建请求的服务[org.hibernate.service.jdbc.connections.spi.ConnectionProvider]         at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:186)         在org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:150)         at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)         在org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:223)         在org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:89)         在org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)         at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)         at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)         在org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:73)         在org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2283)         在org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2279)         在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1748)         在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1788)         在org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:860)         在org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:779)         在org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)         在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)         在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)         ......还有67个     引起:org.hibernate.HibernateException:无法实例化连接提供程序[org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider]         at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:192)         在org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:114)         在org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:54)         at org.hibernate.service.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:69)         at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:176)         ......还有84个     引起:java.lang.ClassCastException:org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider无法强制转换为org.hibernate.service.jdbc.connections.spi.ConnectionProvider         在org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:189)         ......还有88个     2012-10-03 23:57:37.640:警告:oejw.WebAppContext:上下文omjpJettyWebAppContext启动失败{/,文件:/ C:/ jtty / wrk / ContactManager / src / main / webapp /},文件:/ C :/ jtty / WRK /的ContactManager / src目录/主/ web应用/     org.springframework.beans.factory.BeanCreationException:创建名称为' contactDAOImpl'的注册自动连接依赖项失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配字段:private org.hibernate.SessionFactory org.taranov.contactmanager.dao.ContactDAOImpl.sessionFactory;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为' sessionFactory'的bean时出错在ServletContext资源[/WEB-INF/spring/data.xml]中定义:init方法的调用失败;嵌套异常是org.hibernate.service.spi.ServiceException:无法创建请求的服务[org.hibernate.service.jdbc.connections.spi.ConnectionProvider]

依旧......

package org.taranov.contactmanager.dao;

import java.util.List;

import org.taranov.contactmanager.domain.Contact;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class ContactDAOImpl implements ContactDAO {

    @Autowired
    private SessionFactory sessionFactory;

    public void addContact(Contact contact) {
        sessionFactory.getCurrentSession().save(contact);
    }

    @SuppressWarnings("unchecked")
    public List<Contact> listContact() {

        return sessionFactory.getCurrentSession().createQuery("from Contact")
            .list();
    }

    public void removeContact(Integer id) {
        Contact contact = (Contact) sessionFactory.getCurrentSession().load(
                Contact.class, id);
        if (null != contact) {
            sessionFactory.getCurrentSession().delete(contact);
        }

    }
}






    package org.taranov.contactmanager.dao;





    import java.util.List;
    import org.taranov.contactmanager.domain.Contact;

    public interface ContactDAO {

        public void addContact(Contact contact);

        public List<Contact> listContact();

        public void removeContact(Integer id);
    }


web.xml

    <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>
    <listener>
    <listener-class>
    org.springframework.web.context.ContextLoaderListener
    </listener-class>
    </listener>
    <servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
    </servlet-mapping>
    <filter>
    <filter-name>charsetFilter</filter-name>
    <filter-class>
    org.springframework.web.filter.CharacterEncodingFilter
    </filter-class>
    <init-param>
    <param-name>encoding</param-name>
    <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
    <param-name>forceEncoding</param-name>
    <param-value>true</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>charsetFilter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    </web-app>







servlet-context.xml


    > <?xml version="1.0" encoding="UTF-8" ?>  <beans:beans
    > xmlns="http://www.springframework.org/schema/mvc"
    > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    > xmlns:beans="http://www.springframework.org/schema/beans"
    > xsi:schemaLocation="http://www.springframework.org/schema/mvc
    > http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    > http://www.springframework.org/schema/beans
    > http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    > <annotation-driven />  <resources mapping="/resources/**"
    > location="/resources/" />  <beans:bean
    > class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    > <beans:property name="prefix" value="/WEB-INF/views/" /> 
    > <beans:property name="suffix" value=".jsp" />  </beans:bean>
    > <beans:import resource="controllers.xml" />  </beans:beans>








root-context.xml

    > <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:context="http://www.springframework.org/schema/context"
    > xmlns:jee="http://www.springframework.org/schema/jee"
    > xmlns:lang="http://www.springframework.org/schema/lang"
    > xmlns:p="http://www.springframework.org/schema/p"
    > xmlns:tx="http://www.springframework.org/schema/tx"
    > xmlns:util="http://www.springframework.org/schema/util"
    > xsi:schemaLocation="http://www.springframework.org/schema/beans
    > http://www.springframework.org/schema/beans/spring-beans.xsd
    > http://www.springframework.org/schema/aop
    > http://www.springframework.org/schema/aop/spring-aop.xsd
    > http://www.springframework.org/schema/context
    > http://www.springframework.org/schema/context/spring-context.xsd
    > http://www.springframework.org/schema/jee
    > http://www.springframework.org/schema/jee/spring-jee.xsd
    > http://www.springframework.org/schema/lang
    > http://www.springframework.org/schema/lang/spring-lang.xsd
    > http://www.springframework.org/schema/tx
    > http://www.springframework.org/schema/tx/spring-tx.xsd
    > http://www.springframework.org/schema/util
    > http://www.springframework.org/schema/util/spring-util.xsd">
    > <context:annotation-config/> <context:component-scan
    > base-package="org.taranov.contactmanager.dao"/>
    > <context:component-scan
    > base-package="org.taranov.contactmanager.service"/> <import
    > resource="data.xml"/> <import resource="security.xml"/> </beans>

db_server feel fine and in config

    > jdbc.driverClassName= com.mysql.jdbc.Driver
    > jdbc.dialect=org.hibernate.dialect.MySQLDialect
    > jdbc.databaseurl=jdbc:mysql://192.168.80.128:3306
    > jdbc.username=contactmanager jdbc.password=1234

please help =(

1 个答案:

答案 0 :(得分:1)

这部分堆栈跟踪让我怀疑你正在使用Hibernate 4:

Caused by: java.lang.ClassCastException:     
org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider cannot be cast to org.hibernate.service.jdbc.connections.spi.ConnectionProvider

如果您使用的是hibernate4,则需要使用org.springframework.orm.hibernate4.LocalDataSourceConnectionProvider而不是org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider