简体   繁体   English

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

[英]Deploying Hibernate Web Application on Tomcat running on Debian

With reference to my older question , I am having some issues when running a enterprise-scale web application on Linux. 关于我的老问题 ,在Linux上运行企业级Web应用程序时遇到一些问题。 Before investing into a real staging machine, I thought that I should give it a try on Raspbery Pi, but now, we're running the application on a real Debian computer. 在投资购买真正的登台机器之前,我认为应该尝试使用Raspbery Pi,但是现在,我们正在真正的 Debian计算机上运行该应用程序。

The issue is as same as my previous question. 这个问题和我以前的问题一样。

At first, I thought that it is more of a tomcat issue, but now, I am thinking that it is a Raspberry Pi Linux issue. 起初,我认为这更多是tomcat问题,但现在,我认为这是 Raspberry Pi Linux问题。

This exact same configuration works on our windows servers, but I cant figure out why it does not work on the Pi Staging Macine ! 此完全相同的配置可在我们的Windows服务器上使用,但我无法弄清楚为什么它在 Pi Staging Macine上不起作用!


The problem(s): 问题:

The tomcat is not registering the JNDI names which I have defined in the application context and Hibernate is not able to connect to the database even though correct database URL is supplied. tomcat没有注册我在应用程序上下文中定义的JNDI名称,即使提供了正确的数据库URL,Hibernate也无法连接到数据库。

In my $CATALINA_HOME/conf/Catalina/localhost/$appname.xml; 在我的$ 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>

I have defined a Spring bean as; 我将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>

It gives me NamingConventionException saying that stagingDS is not defined. 它给我NamingConventionException表示stagingDS

This might be a Tomcat issue as well, so I am posting the output of version.sh as well. 这也可能是Tomcat的问题,因此我也将发布version.sh的输出。

PuTTY的屏幕截图

Hibernate; 冬眠

I am calling this method to create a session factory 我正在调用此方法来创建会话工厂

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;

    }

The session factory creation is successful, but in my log file, I see these:- 会话工厂创建成功,但是在我的日志文件中,我看到了以下内容:

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.

I have tried putting the JNDI name in 我尝试将JNDI名称放入

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

But the problem still resides. 但是问题仍然存在。

We are still very confused by what it is... Am I doing something wrong? 我们仍然对它到底是什么感到困惑。我在做错什么吗?

It is not a Database Connection Issue. 这不是数据库连接问题。

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.

Usually means that your Database server is down or is in an IP/Hostname other than localhost. 通常意味着您的数据库服务器已关闭或位于localhost以外的IP /主机名中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM