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

北城余情 提交于 2019-12-13 16:32:26

问题


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?


回答1:


Add this property into portal:

portal.security.manager.strategy=none

I had the same problem and this worked for me.



来源:https://stackoverflow.com/questions/18620798/liferay-tomcat-hot-deploy-closes-jndi-connection-how-can-i-keep-it-open

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!