2016-09-01 3 views
1

java.sql.SQLException: No suitable driver found for jdbc:postgresql://localhost:5432/database2되는 SQLException : JDBC에 대한 찾을 수 없습니다 적합 드라이버 : PostgreSQL의

보스 7.1.1

entityManager.getTransaction()

에 의해 슬로우

Class.forName("org.postgresql.Driver"); 
EntityManager entityManager = Persistence.createEntityManagerFactory("database2").createEntityManager(); 
EntityTransaction transaction = entityManager.getTransaction(); 

의 persistence.xml

<?xml version="1.0" encoding="UTF-8"?> 
<persistence xmlns="http://java.sun.com/xml/ns/persistence" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
         http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" 
    version="2.0"> 

    <persistence-unit name="database2" transaction-type="RESOURCE_LOCAL"> 
     <provider>org.hibernate.ejb.HibernatePersistence</provider> 
     <properties> 
      <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" /> 
      <property name="javax.persistence.jdbc.user" value="user" /> 
      <property name="javax.persistence.jdbc.password" value="" /> 
      <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/database2" /> 
      <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" /> 
     </properties> 
    </persistence-unit> 
</persistence> 

디렉토리 구조

EJB: 
    | 
    |- src 
      | 
      |- class1.java 
      |- interface1.java 
      | 
      |- META_INF 
         | 
         |-persistence.xml 

WEB: 
    | 
    |- src 
    |  | 
    |  |- class2.java 
    | 
    |-WebContent 
       | 
       |- WEB-INF 
          | 
          |- lib 
            | 
            |- postgresql-9.1-903.jdbc4.jar 

EAP_HOME/모듈/조직/PostgreSQL을/주 /을 Module.xml

<?xml version="1.0" encoding="UTF-8"?> 
<module xmlns="urn:jboss:module:1.0" name="org.postgresql"> 
    <resources> 
    <resource-root path="postgresql-9.1-903.jdbc4.jar"/> 
    </resources> 
    <dependencies> 
    <module name="javax.api"/> 
    <module name="javax.transaction.api"/> 
    </dependencies> 
</module> 

CLI 명령 :

/subsystem=datasources/jdbc-driver=postgresql:add(driver-name=postgresql,driver-module-name=org.postgresql,driver-xa-datasource-class-name=org.postgresql.Driver)

+3

당신이 있는지 확인해야합니다 –

+2

핵심 모듈 https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6/html-single/Administration_and_Configuration_Guide/index.html#Install_a_JDBC_Driver_as_a_Core_Module1로 JDBC 드라이버를 설치하려고합니다 JDBC 드라이버는 서버의 (JBoss) 소유/lib 폴더에 있습니다. –

+0

@Nicolas Filotto postgresql-9.1-903.jdbc4.jar을 코어 모듈로 설치 한 후에도 동일한 예외가 발생합니다. 다른 아이디어? – user773344

답변

0

는 니콜라스는 설치 말한대로 JDBC 드라이버 (core module

) MANIEST.MF JBoss에 dependency.xml

내가 더 사양이 호환으로 첫 번째 방법을 권장합니다 :

다음 두 가지 방법이 있습니다이 모듈에 의존하면 응용 프로그램을 확인해야합니다. 기본적으로 MANIFEST.MF 파일을 EAR 또는 WAR의 META-INF 디렉토리에 작성해야합니다 (전개되는 모든 항목).

Dependencies: org.postgresql 

자세한 정보를 원하시면 들어 JBoss EAP documentation 또는 JBoss wiki 참조 : 파일에서 만드는 라인은 무엇인가가있을 것입니다. 이게 도움이 되길 바란다!

관련 문제