[英]Deploying Spring MVC web app .war file in tomcat in openshift results in blank page
I have a Spring MVC Web application with MySQL database running on tomcat. 我有一个运行在tomcat上的MySQL数据库的Spring MVC Web应用程序。 I have configured Tomcat 7 (JBoss EWS 2.0), MySQL 5.5 and phpMyAdmin 4.0 on openshift .
我已经在openshift上配置了Tomcat 7(JBoss EWS 2.0),MySQL 5.5和phpMyAdmin 4.0 。 Then I have deployed my .war file following this tutorial .
然后,按照本教程部署了.war文件。 But my .war file doesn't work, I have renamed it to ROOT.war, and in root of openshift application it shows me a blank page.
但是我的.war文件不起作用,我将其重命名为ROOT.war,并且在openshift应用程序的根目录中向我显示了一个空白页。 When I used some sample .war file from internet( for example this one ), everything works perfect.
当我使用一些来自Internet的示例.war文件时( 例如此文件),一切正常。
I thougt maybe the problem is in the database connection, so this is how my datasource in mvc-dipatcher-servlet.xml
looks like with OpenShift's environment variables: 我也许是问题出在数据库连接中,所以这就是我在
mvc-dipatcher-servlet.xml
数据源与OpenShift的环境变量一样的样子:
<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>
I have also tried with hardcoded version but the same result - pretty simple blank page: 我也尝试过使用硬编码版本,但结果相同-非常简单的空白页:
<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>
Is there any solutions for this problem? 这个问题有解决方案吗?
UPDATE With the suggestion of @Artur Malinowski I ran rhc tail - a <appname>
command: This is what I got: 更新在@Artur Malinowski的建议下,我运行了
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)
Finally I have solved the problem which was actually stated here . 最后,我解决了这里实际提到的问题。 I have solved this with the help of this answer .
我已经借助这个答案解决了这个问题 。 And here is my implementation:
这是我的实现:
I have added a listener-class
in my web.xml
: 我在我的
web.xml
添加了一个listener-class
:
<listener>
<listener-class>
az.quiz.utils.MyServletContext
</listener-class>
</listener>
And added the listener class: 并添加了侦听器类:
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");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.