0

I'm trying to deploy an Spring web application that has as dependendy another Spring Application (in this case a jar) where this jar has all the domain definition and database connection info. The database that I'm using is postgresql with the driver:

<dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.3-1102-jdbc41</version>
    </dependency>

in this context I'm having this error:

2014-08-05 11:33:52,463 [http-8082-4] DEBUG org.hibernate.util.JDBCExceptionReporter - Cannot open connection [???]
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Can not create PoolableConnectionFactory (Connection refused. Verify that the hostname and port are correct and that the postmaster is accepting TCP / IP connections.)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
    at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:71)

I dont know what happend with this error because before this change, the web application had all the domain and database connections info.

Other test that I made, how to encapsulate just the domain classes into a jar to be imported by the web application without the connection info but in that case the problem was that the entites doesn't found any transaction manager to execute even when the datasource was created in the same webapplication.

As you can see, the thing is I want to separate the domain model in a module which any other module or project can use it like a dependency.

Cœur
  • 37,241
  • 25
  • 195
  • 267
gleX
  • 595
  • 2
  • 8
  • 22
  • 1
    Google translate says that the error message is *"Can not create PoolableConnectionFactory (Connection refused. Verify that the hostname and port are correct and that the postmaster is accepting TCP / IP connections.)"* – Stephen C Aug 05 '14 at 10:19
  • Ohhh thanks Stephen C, I didn't realize the message was in spanish :) – gleX Aug 05 '14 at 10:27
  • Don't be snarky. The comment is for the benefit of other people reading your Question. You do want people to help you ... don't you? – Stephen C Aug 05 '14 at 10:33

2 Answers2

0

The error message is telling me that your webapp is failing to connect to the database: the postmaster process.

What has happened?

  • The database service may no longer on the host / port that you previously were using.
  • The database service may not be running at the moment.
  • Your webapp (via Spring) may be picking up its database configuration information from the wrong place.

Assuming that you'd know that the database had moved, and that you have checked that the database is running, the last explanation is the likely one.

Now it sounds like you are attempting to pick up the database connection details from a file (e.g. a properties file) in a JAR file. If that is the case, then I'd look for a problem in the way that the details are being located. For example, if you accidentally had two copies of the file (with different details) in different JAR files, then the database connection code would (most likely) use the file that appears first on the webapp's effective classpath. If that's the wrong one, your webapp would use the wrong connection details.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
0

Finally I have my project working with the multiple modules distribution:

  • Spring Web Application
  • Spring Library with hibernate (domain.jar)

After a long research and a lot of problems (ex. entities doesn't see the transactionManager) I did the following changes into my project:

  • Spring Library with Hibernate. I construct the library without the applicationContext.xml, just with the persistence.xml.
  • Spring Web Application.

    • Persistence.xml - Added this line into the properties declaration to reference the library

/WEB-INF/lib/domain-0.1.jar

- applicationContext.xml - Bean reference to HibernateJpaDialect

<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>    

<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
    <property name="jpaDialect" ref="jpaDialect"/>
</bean>

In this next links you can find more explanation for this changes.

JPA - multiple jars defining @Entity objects

Why to use jpadialect in JpaTransactionManager

Community
  • 1
  • 1
gleX
  • 595
  • 2
  • 8
  • 22