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( at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(

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.

人吐槽 人点赞



用户名: 密码:
验证码: 匿名发表


查看评论:Liferay/Tomcat “hot-deploy” closes JNDI connection, how can I keep it open?