在 openshift 中部署 Spring MVC Web app .war 文件会导致空白页



我有一个Spring MVC Web应用程序,MySQL数据库运行在tomcat上。我已经在openshift上配置了Tomcat 7(JBoss EWS 2.0),MySQL 5.5和phpMyAdmin 4.0。然后,我按照本教程部署了我的 .war 文件。但是我的.war文件不起作用,我已将其重命名为ROOT.war,并且在openshift应用程序的根目录中,它向我显示了一个空白页。当我使用来自互联网的一些示例 .war 文件(例如这个)时,一切都很完美。

我认为问题可能出在数据库连接上,所以这就是我在 OpenShift 环境变量中mvc-dipatcher-servlet.xml数据源的样子:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://${OPENSHIFT_MYSQL_DB_HOST}:${OPENSHIFT_MYSQL_DB_PORT}/${OPENSHIFT_APP_NAME}?characterEncoding=UTF-8"/>
    <property name="username" value="${OPENSHIFT_MYSQL_DB_USERNAME}"/>
    <property name="password" value="${OPENSHIFT_MYSQL_DB_PASSWORD}"/>
</bean>

我也尝试过硬编码版本,但结果相同 - 非常简单的空白页:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://127.0.0.1:3306/myDatabaseName?characterEncoding=UTF-8"/>
    <property name="username" value="myRootUserName"/>
    <property name="password" value="MyPassword"/>
</bean>

这个问题有什么解决方案吗?

更新在@Artur马林诺夫斯基的建议下,我运行了rhc tail - a <appname>命令:这就是我得到的:

DL is deprecated, please use Fiddle
==> app-root/logs/jbossews.log <==
Dec 30, 2014 7:06:06 AM org.apache.catalina.loader.WebappClassLoader clearRefere
ncesJdbc
SEVERE: The web application [/quiz] registered the JDBC driver [com.mysql.jdbc.D
river] but failed to unregister it when the web application was stopped. To prev
ent a memory leak, the JDBC Driver has been forcibly unregistered.
Dec 30, 2014 7:06:06 AM org.apache.catalina.loader.WebappClassLoader clearRefere
ncesThreads
SEVERE: The web application [/quiz] appears to have started a thread named [Aban
doned connection cleanup thread] but has failed to stop it. This is very likely
to create a memory leak.
Dec 30, 2014 7:06:06 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deployment of web application archive /var/lib/openshift/54a274c6e0b8cd33d
10000a4/app-root/runtime/dependencies/jbossews/webapps/quiz.war has finished in
15,066 ms
Dec 30, 2014 7:06:06 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-127.4.37.1-8080"]
Dec 30, 2014 7:06:06 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 15415 ms
==> app-root/logs/phpmyadmin.log <==
[Tue Dec 30 07:03:35 2014] [notice] caught SIGWINCH, shutting down gracefully
- - - [30/Dec/2014:07:03:35 -0500] "OPTIONS * HTTP/1.0" 200 - "-" "Apache/2.2.15
 (Red Hat) (internal dummy connection)"
[Tue Dec 30 07:04:06 2014] [notice] SELinux policy enabled; httpd running as con
text unconfined_u:system_r:openshift_t:s0:c2,c79
[Tue Dec 30 07:04:06 2014] [notice] Digest: generating secret for digest authent
ication ...
[Tue Dec 30 07:04:06 2014] [notice] Digest: done
[Tue Dec 30 07:04:06 2014] [notice] Apache/2.2.15 (Unix) PHP/5.3.3 configured --
 resuming normal operations
[Tue Dec 30 07:05:31 2014] [notice] SIGHUP received.  Attempting to restart
[Tue Dec 30 07:05:32 2014] [notice] Digest: generating secret for digest authent
ication ...
[Tue Dec 30 07:05:32 2014] [notice] Digest: done
[Tue Dec 30 07:05:32 2014] [notice] Apache/2.2.15 (Unix) PHP/5.3.3 configured --
 resuming normal operations
==> app-root/logs/mysql.log <==
141230  7:05:12 InnoDB: highest supported file format is Barracuda.
141230  7:05:13  InnoDB: Waiting for the background threads to start
141230  7:05:14 InnoDB: 5.5.40 started; log sequence number 1755443
141230  7:05:14 [Note] Server hostname (bind-address): '127.4.37.2'; port: 3306
141230  7:05:14 [Note]   - '127.4.37.2' resolves to '127.4.37.2';
141230  7:05:14 [Note] Server socket created on IP: '127.4.37.2'.
141230  7:05:14 [Warning] 'proxies_priv' entry '@ root@ex-std-node501.prod.rhclo
ud.com' ignored in --skip-name-resolve mode.
141230  7:05:14 [Note] Event Scheduler: Loaded 0 events
141230  7:05:14 [Note] /opt/rh/mysql55/root/usr/libexec/mysqld: ready for connec
tions.
Version: '5.5.40'  socket: '/var/lib/openshift/54a274c6e0b8cd33d10000a4/mysql//s
ocket/mysql.sock'  port: 3306  MySQL Community Server (GPL)

最后,我解决了这里实际陈述的问题。我已经在这个答案的帮助下解决了这个问题。这是我的实现:

我在web.xml中添加了一个listener-class

<listener>
    <listener-class>
        az.quiz.utils.MyServletContext
    </listener-class>
</listener>

并添加了侦听器类:

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;
public class MyServletContext implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("Context created");
    }
    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        Enumeration<Driver> drivers = DriverManager.getDrivers();
        while (drivers.hasMoreElements()) {
            Driver driver = drivers.nextElement();
            try {
                DriverManager.deregisterDriver(driver);
                System.out.println(String.format("deregistering jdbc driver: %s", driver));
            } catch (SQLException e) {
                System.out.println(String.format("Error deregistering driver %s", driver));
            }
        }
        System.out.println("Context destroyed");
    }
}

相关内容

  • 没有找到相关文章

最新更新