Liferay/Tomcat的“热部署"关闭JNDI连接,如何保持打开状态? [英] Liferay/Tomcat "hot-deploy" closes JNDI connection, how can I keep it open?
问题描述
首先,我不确定该行为是否来自Liferay或Tomcat.
First, I'm not sure if the behavior comes from Liferay or Tomcat.
我在Liferay中有一个portlet,它使用JNDI连接和JDBC模板,这些portlet都配置了spring(我没有使用Liferay Service Builder或Liferay的任何东西,我只是将其用作Portlet容器).
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).
启动服务器时,JNDI连接有效(我能够从数据库检索数据). 当我在liferay中热部署"我的portlet WAR时,连接被关闭. 因此,当我尝试访问数据时,出现此错误:
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);
}
}
jdbcTemplate的配置(来自DAO类)
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;
}
访问数据(从DAO类):
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;
}
当我从控制器调用"findAllObjects"方法时,此方法将起作用,直到我重新部署Portlet WAR.然后,如果在方法内部使用断点,则可以看到连接已关闭(closed = true).
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?
推荐答案
将此属性添加到门户:
portal.security.manager.strategy=none
我遇到了同样的问题,这对我有用.
I had the same problem and this worked for me.
这篇关于Liferay/Tomcat的“热部署"关闭JNDI连接,如何保持打开状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!