部署 Tomcat 后 Java/Spring 应用卡住

标签 java spring spring-mvc tomcat

我使用 Java/Spring Mvc 网络应用开发比特币钱包。部署后,应用程序卡住了,什么也没有发生。我的意思是登录页面在本地主机中打开。之后,它应该在同步方面取得一些进展,并且按钮/下拉菜单应该处于 Activity 状态。没有错误。我得到的唯一日志是一些 WARNNINGINFO,

[2017-06-28 11:25:03,820] Artifact BitcoinWalletApp:war exploded: Artifact is deployed successfully
[2017-06-28 11:25:03,820] Artifact BitcoinWalletApp:war exploded: Deploy took 6,195 milliseconds
org.hibernate.hql.internal.QueryTranslatorFactoryInitiator: 06/28/2017 11:25:04 - HHH000397: Using ASTQueryTranslatorFactory

28-Jun-2017 11:12:49.818 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/Applications/Tomcat-8.5.15/webapps/manager]
28-Jun-2017 11:12:49.845 WARNING [localhost-startStop-1] org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory.getObjectInstance Name = spring Property maxActive is not used in DBCP2, use maxTotal instead. maxTotal default value is 8. You have set value of "50" for "maxActive" property, which is being ignored.
28-Jun-2017 11:12:49.845 WARNING [localhost-startStop-1] org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory.getObjectInstance Name = spring Property maxWait is not used in DBCP2 , use maxWaitMillis instead. maxWaitMillis default value is -1. You have set value of "10000" for "maxWait" property, which is being ignored.
28-Jun-2017 11:12:49.855 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/Applications/Tomcat-8.5.15/webapps/manager] has finished in [36] ms

database-context.xml文件中,提供了JNDI配置,

    <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.2.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd">

    <context:annotation-config></context:annotation-config>

    <context:component-scan base-package="mobi.puut.database">
    </context:component-scan>

    <beans profile="production">
        <context:property-placeholder
                location="classpath:mobi/puut/config/jdbc.properties"/>

        <!--<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"-->
              <!--destroy-method="close">-->
            <!--<property name="driverClassName" value="${jdbc.driver}"></property>-->
            <!--<property name="url" value="${jdbc.url}"></property>-->
            <!--<property name="password" value="${jdbc.password}"></property>-->
            <!--<property name="username" value="${jdbc.username}"></property>-->
        <!--</bean>-->

        <jee:jndi-lookup jndi-name="jdbc/spring" id="dataSource"
                         expected-type="javax.sql.DataSource">
        </jee:jndi-lookup>

        <bean id="sessionFactory"
              class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
            <property name="dataSource" ref="dataSource"></property>
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
                    <!--<prop key="hibernate.hbm2ddl.auto">create</prop>-->
                    <prop key="hibernate.show_sql">false</prop>
                    <prop key="hibernate.generate_statistics">false</prop>
                    <prop key="hibernate.use_sql_comments">false</prop>
                </props>
            </property>

            <property name="packagesToScan" value="mobi.puut.entities"/>
        </bean>

        <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
            <property name="sessionFactory" ref="sessionFactory"/>
        </bean>

        <tx:annotation-driven transaction-manager="transactionManager"/>


        <bean id="exceptionTranslator"
              class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor">
        </bean>
    </beans>
</beans>

web.xml中,数据库引用如下,

<description>Spring Database</description>
    <resource-ref>
        <description>DB Connection</description>
        <res-ref-name>jdbc/spring</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

Tomcat 中,Resource 信息由 conf/context.xml 提供,如下所示,

<Resource name="jdbc/spring" auth="Container" type="javax.sql.DataSource"
           maxActive="50" maxIdle="30" maxWait="10000"
           username="testname" password="testpassword"
           driverClassName="com.mysql.jdbc.Driver"
           url="jdbc:mysql://localhost:3306/wallet"/>

如果需要,我可以提供更多信息。问题是什么以及如何解决?

更新

我已经更改了 conf/context.xml 中的属性,如日志中所述:maxTotal 代替 maxActive 和 maxWaitMillis 代替 maxWait 并且 WARNING 消失了。它仍然卡住了。

28-Jun-2017 15:54:05.451 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/Applications/Tomcat-9.0.0.M21/webapps/manager]
28-Jun-2017 15:54:05.486 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/Applications/Tomcat-9.0.0.M21/webapps/manager] has finished in [34] ms

最佳答案

您是否尝试过更改 conf/context.xml 中的属性,如日志中所述:maxTotal 而不是 maxActivemaxWaitMillis 而不是 maxWait

关于部署 Tomcat 后 Java/Spring 应用卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44794329/

相关文章:

java - 在 Spring 5.1.0 中加载和切换属性源的最优雅的方式是什么?

java - Spring MVC 测试中带有过滤器的 JsonPath 表达式

javascript - 在新浏览器窗口的响应中显示 PDF 字节流

java - SOAP 代理客户端的 Spring Boot 通用异常处理程序

java - Spark 多次对数据库运行查询

java - 如何使用 MDC 在 log4j2 中动态创建日志文件名

java - 如何从另一个范围中过滤掉一个范围内的数字

java - 我可以将复杂对象作为输入传递给 Spring WebFlow 子流吗?

java - 如何链接以纯文本形式出现的 URL?

data-binding - spring mvc绑定(bind)到2个具有相同字段的对象