2017-05-11 2 views
0

J'ai essayé d'implémenter un projet java spring hibernate simple en utilisant Sql Server 2005 et maven. Je reçois cette erreur comme ci-dessous sur le démarrage de Tomcat 8 Server. Je comprends que cela a quelque chose à voir avec les pots que j'utilise. Toute indication à ce sujet sera extrêmement utile.Printemps MVC Hibernate: AbstractMethodError: net.sourceforge.jtds.jdbc.ConnectionJDBC3.isValid (I) Z

ERROR: org.springframework.web.servlet.DispatcherServlet - Context initialization failed 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]: Invocation of init method failed; nested exception is java.lang.AbstractMethodError: net.sourceforge.jtds.jdbc.ConnectionJDBC3.isValid(I)Z 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:684) 
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) 
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) 
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658) 
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624) 
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672) 
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543) 
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484) 
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) 
at javax.servlet.GenericServlet.init(GenericServlet.java:158) 
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1238) 
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1151) 
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1038) 
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5027) 
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5337) 
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147) 
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407) 
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397) 
at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
at java.lang.Thread.run(Thread.java:745) 
Caused by: java.lang.AbstractMethodError: net.sourceforge.jtds.jdbc.ConnectionJDBC3.isValid(I)Z 
at org.apache.commons.dbcp2.DelegatingConnection.isValid(DelegatingConnection.java:918) 
at org.apache.commons.dbcp2.PoolableConnection.validate(PoolableConnection.java:283) 
at org.apache.commons.dbcp2.PoolableConnectionFactory.validateConnection(PoolableConnectionFactory.java:357) 
at org.apache.commons.dbcp2.BasicDataSource.validateConnectionFactory(BasicDataSource.java:2307) 
at org.apache.commons.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:2290) 
at org.apache.commons.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2039) 
at org.apache.commons.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1533) 
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:139) 
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcServicesImpl.java:279) 
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:124) 
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111) 
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234) 
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206) 
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885) 
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843) 
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928) 
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:343) 
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:431) 
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:416) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549) 
... 28 more 

J'ai essayé toutes les solutions disponibles ici, rien de très utile.

Mon pom.xml ressemble à ceci:

<?xml version="1.0" encoding="UTF-8"?> 
<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>net.codejava</groupId> 
<artifactId>SpringMvcHibernateXML</artifactId> 
<name>SpringMvcHibernateXML</name> 
<packaging>war</packaging> 
<version>1.0.0-BUILD-SNAPSHOT</version> 

<properties> 
    <java-version>1.7</java-version> 
    <org.springframework-version>4.0.3.RELEASE</org.springframework-version> 
</properties> 

<dependencies> 
    <!-- Spring --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context</artifactId> 
     <version>${org.springframework-version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-webmvc</artifactId> 
     <version>${org.springframework-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-orm</artifactId> 
     <version>${org.springframework-version}</version> 
     <type>jar</type> 
     <scope>compile</scope> 
    </dependency> 

    <!-- Hibernate --> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-core</artifactId> 
     <version>4.3.5.Final</version> 
    </dependency> 

    <!-- Servlet --> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>javax.servlet-api</artifactId> 
     <version>3.1.0</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>javax.servlet.jsp</groupId> 
     <artifactId>javax.servlet.jsp-api</artifactId> 
     <version>2.3.1</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>jstl</groupId> 
     <artifactId>jstl</artifactId> 
     <version>1.2</version>  
    </dependency> 



<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-dbcp2 --> 
<dependency> 
    <groupId>org.apache.commons</groupId> 
    <artifactId>commons-dbcp2</artifactId> 
    <version>2.1.1</version> 
</dependency> 

<dependency> 
    <groupId>net.sourceforge.jtds</groupId> 
    <artifactId>jtds</artifactId> 
    <version>1.3.1</version> 
</dependency> 
</dependencies> 
<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-eclipse-plugin</artifactId> 
      <version>2.9</version> 
      <configuration> 
       <additionalProjectnatures> 
        <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature> 
       </additionalProjectnatures> 
       <additionalBuildcommands> 
        <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand> 
       </additionalBuildcommands> 
       <downloadSources>true</downloadSources> 
       <downloadJavadocs>true</downloadJavadocs> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.5.1</version> 
      <configuration> 
       <source>1.6</source> 
       <target>1.6</target> 
       <compilerArgument>-Xlint:all</compilerArgument> 
       <showWarnings>true</showWarnings> 
       <showDeprecation>true</showDeprecation> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>exec-maven-plugin</artifactId> 
      <version>1.2.1</version> 
      <configuration> 
       <mainClass>org.test.int1.Main</mainClass> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

web.xml va ici:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> 

<!-- The definition of the Root Spring Container shared by all Servlets and Filters --> 
<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>/WEB-INF/spring/root-context.xml</param-value> 
</context-param> 

<!-- Creates the Spring Container shared by all Servlets and Filters --> 
<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

<!-- Processes application requests --> 
<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> 

servlet-context.xml comme ci-dessous

:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://www.springframework.org/schema/beans" 
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:tx="http://www.springframework.org/schema/tx" 
xsi:schemaLocation="http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc.xsd 
    http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx.xsd 
    http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context.xsd"> 

<context:component-scan base-package="net.codejava.spring" /> 
<!-- DispatcherServlet Context: defines this servlet's request-processing 
    infrastructure --> 

<!-- Enables the Spring MVC @Controller programming model --> 
<mvc:annotation-driven /> 


<!-- Handles HTTP GET requests for /resources/** by efficiently serving 
    up static resources in the ${webappRoot}/resources directory --> 
<mvc:resources mapping="/resources/**" location="/resources/" /> 

<!-- Resolves views selected for rendering by @Controllers to .jsp resources 
    in the /WEB-INF/views directory --> 
<bean 
    class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="prefix" value="/WEB-INF/views/" /> 
    <property name="suffix" value=".jsp" /> 
</bean> 


<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"> 
    <property name="driverClassName"><value>net.sourceforge.jtds.jdbc.Driver</value></property> 
    <property name="url"><value>jdbc:jtds:sqlserver://servernameurl</value></property> 
    <property name="password"><value>******</value></property> 
    <property name="username"><value>admin</value></property> 
</bean> 

<bean id="sessionFactory" 
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 
    <property name="dataSource" ref="dataSource" /> 
    <property name="configLocation" value="classpath:hibernate.cfg.xml" /> 
</bean> 

<tx:annotation-driven /> 
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> 
    <property name="sessionFactory" ref="sessionFactory" /> 
</bean> 

<bean id="userDao" class="net.codejava.spring.dao.UserDAOImpl"> 
    <constructor-arg ref="sessionFactory" /> 
</bean> 

hibernate.cfg.xml va ici:

<?xml version='1.0' encoding='utf-8'?> 
<!DOCTYPE hibernate-configuration PUBLIC 
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> 
<hibernate-configuration>   
<session-factory> 
<property 
name="dialect">org.hibernate.dialect.SQLServer2005Dialect</property> 
<property name="show_sql">true</property> 
<mapping resource="net/codejava/spring/model/User.hbm.xml"/> 
</session-factory> 
</hibernate-configuration> 

Répondre

0

Modification de la classe pour dataSource à

org.springframework.jdbc.datasource.DriverManagerDataSource

dans le fichier servlet-context.xml a résolu le problème. Le dataSource ressemble maintenant à ceci:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
<property name="driverClassName"><value>net.sourceforge.jtds.jdbc.Driver</value></property> 
<property name="url"><value>jdbc:jtds:sqlserver://servernameurl</value></property> 
<property name="password"><value>******</value></property> 
<property name="username"><value>admin</value></property> 

0

Ajouter cette S'il vous plaît dépendance et essayer:

<dependency> 
    <groupId>net.sourceforge.jtds</groupId> 
    <artifactId>jtds</artifactId> 
    <version>1.3.1</version> 
</dependency> 
+0

Son déjà là – Reema