Liferay/Tomcat “hot-deploy” closes JNDI connection, how can I keep it open?

First, I'm not sure if the behavior comes from Liferay or Tomcat.

I have a portlet in Liferay that uses a JNDI connection and JDBC template all configured with spring (I'm not using Liferay service builder or anything from Liferay, I'm just using it as a portlet container).

When I start the server, the JNDI connection works (I'm able to retreive data from a database). When I "hot deploy" my portlet WAR in liferay, the connection is closed. So when I try to access the data, I get this error :

java.sql.SQLException: Data source is closed at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1362) at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)

DataSource configuration (which is scanned via a component-scan statement) :

@Bean public DataSource myDbDataSource() { String jndiName = "java:comp/env/jdbc/MyDB"; try { Context jndi = new InitialContext(); DataSource ds = (DataSource) jndi.lookup(jndiName); return ds; } catch (NamingException e) { throw new IllegalStateException(e.getMessage(), e); } }

Configuration of jdbcTemplate (from a DAO class)

private JdbcTemplate jdbcTemplate; private DataSource myDbDataSource; @Autowired public void setDataSource(DataSource myDbDataSource) { this.jdbcTemplate = new JdbcTemplate(myDbDataSource); this.myDbDataSource = myDbDataSource; }

Accessing the data (from a DAO class) :

@Override public List<MyObject> findAllObjects() { String sql = "SELECT * FROM objects"; List<MyObject> objects = (List<MyObject>) jdbcTemplate.query(sql, new BeanPropertyRowMapper<MyObject>(MyObject.class)); return lobjects; }

When I call the "findAllObjects" methods from a controller this works until I redeploy my portlet WAR. Then, if I use a breakpoint inside the method, I can see that the connection is closed (closed = true).

Is there anyway that I can re-establish the connection?


Add this property into portal:


I had the same problem and this worked for me.


  • Use property file's property in spring mvc configuration servlet xml
  • What is the Spring 5 JDBC approach when nativeJdbcExtractor is needed?
  • Maven and Eclipse - DON'T download dependency
  • Spring Multiple PropertyPlaceholderConfigurer files and database
  • Spring Batch CompositeItemWriter Transaction Roll back issue
  • Grails application is not running after installing Grails activiti plugin
  • How can we cache HLS video url once streamed
  • call a java program from a webapp in tomcat server - the java program is out side of tomcat server
  • Find VMID for running instance
  • Can long-polling be achieved in Restlet by just making the thread sleep?
  • File extension of zlib zipped html page?
  • iOS Cordova first plugin - plugin.xml to inject a feature
  • Is there some graphical way to create my own configuration file on SonarLint?
  • Row to Column conversion in Talend
  • Unable to get column index with table.getColumn method using custom table Model
  • Visual Studio 2010 debugger build correctly - compiler pdb and linker pdb not in synch?
  • Oledb connection string for excel files
  • Problem deserializing objects from cache on MyBatis 3/Java
  • Spark fat jar to run multiple versions on YARN
  • Read a local file using javascript
  • ImageMagick, replace semi-transparent white with opaque white
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • CSS Linear-gradient formatting issue accross different browsers
  • Cannot connect to cassandra from Spark
  • Master page gives error
  • Spring security and special characters
  • Nant, Vault & Windows Integrated Authentication
  • PHP - How to update data to MySQL when click a radio button
  • Counter field in MS Access, how to generate?
  • Cross-Platform Protobuf Serialization
  • Javascript + PHP Encryption with pidCrypt
  • Websockets service method fails during R startup
  • Alternatives to the OPTIONAL fallback SPARQL pattern?
  • How to format a variable of double type
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • coudnt use logback because of log4j
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Linking SubReports Without LinkChild/LinkMaster
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • JaxB to read class hierarchy