gpt4 book ai didi

java - 在 Debian 上运行的 Tomcat 上部署 Hibernate Web 应用程序

转载 作者:太空宇宙 更新时间:2023-11-04 10:34:59 24 4
gpt4 key购买 nike

引用我的older question ,我在 Linux 上运行企业级 Web 应用程序时遇到了一些问题。在购买一台真正的暂存机器之前,我认为我应该在 Raspbery Pi 上试一试,但现在,我们正在真正 Debian 计算机上运行该应用程序。

这个问题和我之前的问题一样。

At first, I thought that it is more of a tomcat issue, but now, I amthinking that it is a Raspberry Pi Linux issue.

This exact same configuration works on our windows servers, but I cantfigure out why it does not work on the Pi Staging Macine!


问题:

tomcat 没有注册我在应用程序上下文中定义的 JNDI 名称,即使提供了正确的数据库 URL,Hibernate 也无法连接到数据库。

在我的 $CATALINA_HOME/conf/Catalina/localhost/$appname.xml 中;

<?xml version="1.0" encoding="UTF-8"?>
<Context antiResourceLocking="false" privileged="true" cookies="true">
<Resource name="stagingDS" auth="Container" type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/preview"
username="root" password="root" />
</Context>

我定义了一个 Spring bean;

    <bean id="velocityConfig"
class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">

<property name="velocityProperties">

<map>

<entry key="resource.loader" value="ds" />
<entry key="ds.resource.loader.class"
value="com.simplestack.velocity.config.SimpleStackDataSourceResourceLoader" />
<entry key="ds.resource.loader.resource.table" value="Catalog" />
<entry key="ds.resource.loader.resource.keycolumn" value="name" />
<entry key="ds.resource.loader.resource.templatecolumn" value="html" />
<entry key="ds.resource.loader.resource.defaultVendorId"
value="1" />
<entry key="ds.resource.loader.resource.defaultSiteId" value="20160109144" />
<entry key="ds.resource.loader.resource.datasource" value="java:comp/env/stagingDS" />
<entry key="ds.resource.loader.resource.timestampcolumn"
value="lastmod" />

</map>

</property>
</bean>

它给我 NamingConventionExceptionstagingDS 没有定义。

这也可能是 Tomcat 的问题,所以我也发布了 version.sh 的输出。

Screenshot of PuTTY

hibernate ;

我正在调用这个方法来创建一个 session 工厂

protected static SessionFactory buildSessionFactory(File cfgfile, File[] hbmfiles, String dburl, String dbuser, String dbpassword, String dbdriver, String treecacheConfigFile) 
throws Exception{
logger.info("Hibernate Configuration File Path:"+cfgfile.getPath());
for (int i=0; i<hbmfiles.length; i++)
logger.info("Hibernate Mapping File Path:"+hbmfiles[i].getPath());
logger.info("Hibernate Using JDBC, dburl:"+dburl+" dbuser:"+dbuser+" dbdriver:"+dbdriver);

Configuration hibernateConfig = new Configuration();
for (int i=0; i<hbmfiles.length; i++)
hibernateConfig = addHbmFile(hibernateConfig, hbmfiles[i]);

// TODO: Add the audit interceptors
// AuditInterceptor auditInterceptor = new AuditInterceptor();
// addDefaultInterceptor(hibernateConfig, auditInterceptor);
// addEventListeners(hibernateConfig);

hibernateConfig.configure(cfgfile);
logger.info("Configfile:"+cfgfile);

if (treecacheConfigFile != null){
hibernateConfig.setProperty("hibernate.cache.configuration_file", treecacheConfigFile);
logger.info("hibernate.cache.configuration_file:"+treecacheConfigFile);
}

hibernateConfig.setProperty("hibernate.connection.url", dburl);
hibernateConfig.setProperty("hibernate.connection.username", dbuser);
hibernateConfig.setProperty("hibernate.connection.password", dbpassword);
hibernateConfig.setProperty("hibernate.connection.driver_class", dbdriver);


SessionFactory sessionFactory = hibernateConfig.buildSessionFactory();
//TODO:set a separate session factory
// auditInterceptor.setSessionFactory(sessionFactory);

return sessionFactory;

}

session 工厂创建成功,但在我的日志文件中,我看到这些:-

2016-06-15 08:04:54,504 INFO  [com.simplestack.SessionFactoryPool] Building Hibernate STAGING Session Factory...
2016-06-15 08:04:54,504 INFO [com.simplestack.SessionFactoryPool] Hibernate Configuration File Path:/SimpleStack/tomcat/webapps/staging/WEB-INF/hibernatecfg/hibernate_mysql.cfg.xml
2016-06-15 08:04:54,505 INFO [com.simplestack.SessionFactoryPool] Hibernate Mapping File Path:/SimpleStack/tomcat/webapps/staging/WEB-INF/hibernate
2016-06-15 08:04:54,505 INFO [com.simplestack.SessionFactoryPool] Hibernate Using JDBC, dburl:jdbc:mysql://localhost:3306/preview dbuser:root dbdriver:com.mysql.jdbc.Driver
2016-06-15 08:04:55,173 WARN [org.hibernate.internal.util.xml.DTDEntityResolver] HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
2016-06-15 08:04:55,284 WARN [org.hibernate.internal.util.xml.DTDEntityResolver] HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
2016-06-15 08:04:55,327 WARN [org.hibernate.internal.util.xml.DTDEntityResolver] HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
2016-06-15 08:04:55,380 WARN [org.hibernate.internal.util.xml.DTDEntityResolver] HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
2016-06-15 08:04:55,408 WARN [org.hibernate.internal.util.xml.DTDEntityResolver] HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
2016-06-15 08:04:55,434 WARN [org.hibernate.internal.util.xml.DTDEntityResolver] HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
2016-06-15 08:04:55,459 WARN [org.hibernate.internal.util.xml.DTDEntityResolver] HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
2016-06-15 08:04:55,483 WARN [org.hibernate.internal.util.xml.DTDEntityResolver] HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
2016-06-15 08:04:55,505 WARN [org.hibernate.internal.util.xml.DTDEntityResolver] HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
2016-06-15 08:04:55,514 INFO [com.simplestack.SessionFactoryPool] Configfile:/SimpleStack/tomcat/webapps/staging/WEB-INF/hibernatecfg/hibernate_mysql.cfg.xml
2016-06-15 08:04:55,882 WARN [org.hibernate.mapping.RootClass] HHH000038: Composite-id class does not override equals(): com.simplestack.hibernate.domainmodel.Siteproperty
2016-06-15 08:04:55,883 WARN [org.hibernate.mapping.RootClass] HHH000039: Composite-id class does not override hashCode(): com.simplestack.hibernate.domainmodel.Siteproperty
2016-06-15 08:04:55,928 WARN [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] HHH000022: c3p0 properties were encountered, but the org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider provider class was not found on the classpath; these properties are going to be ignored.
2016-06-15 08:04:56,466 WARN [org.hibernate.engine.jdbc.internal.JdbcServicesImpl] HHH000342: Could not obtain connection to query metadata : Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

我尝试将 JNDI 名称放入

  1. $CATALINA_HOME/conf/Catalina/localhost/$appname.xml
  2. $CATALINA_HOME/webapps/$appname/META-INF/context.xml
  3. $CATALINA_HOME/conf/context.xml
  4. $CATALINA_HOME/conf/server.xml

但问题依旧。

我们仍然很困惑它是什么......我做错了什么吗?

最佳答案

这不是数据库连接问题。

Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

通常意味着您的数据库服务器已关闭或位于本地主机以外的 IP/主机名中。

关于java - 在 Debian 上运行的 Tomcat 上部署 Hibernate Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38025068/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com