【问题标题】:What should the result of extraction be after deploying a Clojure WAR web application to Tomcat?将 Clojure WAR Web 应用程序部署到 Tomcat 后,提取的结果应该是什么?
【发布时间】:2016-01-28 06:24:52
【问题描述】:

附录:我已经设法让我的 Clojure 应用程序在本地安装的 Tomcat 8.0.28 上运行,所以我真的不知道发生了什么。它涉及将我的数据库连接的 IP 绑定到主机名(以便在部署时它将使用某种 sym-link)和一堆其他修复,例如基于上下文的路由,所以我真的不知道为什么我不能尽管可以直接访问它,但不能让这个东西在另一台机器上的 Tomcat 安装上运行......


我正在使用我命名为emt-admin 的 Ring 和 Compojure(结合 YESQL 和 Friend)在 Clojure 中构建一个相对基本的 CRUD 应用程序,到目前为止,我的代码的构建方式是使用 lein ring server-headless 对其进行测试导致基本没有问题。然而,在使用lein ring uberwar 写成in this website 之后,我发现在导航到/webapps/emt-admin/ 中指示的路径后,这将类似于http://<address>:8080/emt-admin(因为我的Tomcat 安装在与我的开发机器分开的服务器上运行)我得到一个空白页并自动定向到http://<address>:8080/login

我想确认一下,在Tomcat安装部署WAR文件时,应该只有WEB-INFMETA-INF这两个文件夹吧?我所有的静态资源都在 WEB-INF 文件夹的子目录中,我不知道是否正在提供我的静态文件,因为当我导航到我部署的网络应用程序时,我得到一个空白页面。

who made this 的人在 StackOverflow 上提出了一个关于它的问题,对他的代码进行了一些修改,以使应用程序更加“上下文友好”,但我并不完全理解他的 diff 更改。

编辑:我一直在尝试自己解决这个问题,并且一直在调查我的 Tomcat 安装日志:

29-Oct-2015 11:47:15.145 INFO [localhost-startStop-2] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive /opt/apache-tomcat-8.0.15/webapps/emt-admin.war
29-Oct-2015 11:49:31.133 SEVERE [localhost-startStop-2] org.apache.catalina.core.StandardContext.startInternal Error listenerStart
29-Oct-2015 11:49:31.145 SEVERE [localhost-startStop-2] org.apache.catalina.core.StandardContext.startInternal Context [/emt-admin] startup failed due to previous errors
29-Oct-2015 11:49:31.147 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web application [emt-admin] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
29-Oct-2015 11:49:31.148 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [emt-admin] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)
 com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43)
29-Oct-2015 11:49:31.150 INFO [localhost-startStop-2] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive /opt/apache-tomcat-8.0.15/webapps/emt-admin.war has finished in 136,005 ms

“Error listenerStart”背后的含义是什么?

我的核心处理程序如下所示:

(ns reporter.core
  (:require [reporter.views.start :as start]
            [reporter.routes.home :as home]
            [compojure.core :as compojure :refer (GET defroutes)]
            [taoensso.timbre :as timbre]
            ring.adapter.jetty)
(:gen-class))

(def site-appli (compojure/routes
                       home/secured-appli))

(defn run
  []
  (defonce privserver
    (ring.adapter.jetty/run-jetty #'site-appli {:port 3000 :join? false})))

过了一会儿它就死了:

29-Oct-2015 11:53:35.767 SEVERE [http-nio-8080-exec-18] org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun 
 java.lang.OutOfMemoryError: PermGen space

进一步检查日志给了我我认为的罪魁祸首:

29-Oct-2015 11:49:31.133 SEVERE [localhost-startStop-2] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class reporter.listener
 com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

我将看看如果我修复我的数据库连接规范会发生什么

【问题讨论】:

    标签: java tomcat clojure war compojure


    【解决方案1】:

    好吧,看来我终于设法让这该死的东西工作了,所以我会回答我自己的问题。为了列出我所做的事情,我不得不冒昧地从我的代码中编辑某些敏感信息,但我的总体观点应该仍然很清楚。 我还应该提到,实际控制我尝试访问的服务器的人将 PermGen 大小增加到 10g

    数据库规范

    我必须修改我的数据库连接规范,使其看起来像这样:

    (ns reporter.db.core
      (:require
       [clojure.java.jdbc :as jdbc]
       [yesql.core :refer [defqueries]]
       [taoensso.timbre :as timbre]))
    
    (def connprod
      {:classname "com.mysql.jdbc.Driver"
       :subprotocol "mysql"
       :subname "//db-emt.my_domain.com/match_ticker" ; the name of my database
       :user "my_user_name"
       :password "my_password"})
    
    (defqueries "sql/queries.sql" {:connection connprod})
    

    在我的开发机器上,我必须将db-emt.my_domain.com 放入我的hosts 文件并将其链接到分配给它的公共IP。原来:subname直接指向IP。

    数据库事务

    修改连接规范后,为了安全起见,我决定使用clojure.java.jdbcwith-db-transaction 包装我的YESQL 事务。我实际上不确定这是否是必要的步骤,但我宁愿安全而不是抱歉。

    上下文路由

    我忘记包含 Hiccup wrap-base-url 中间件。哎呀

    此外,我决定用 (include-js)(include-html) 之类的东西替换我的裸体 Hiccup 引用。在某些情况下,我还使用了(form-to) 以确保确定。

    所以现在在我的 Tomcat 服务器日志中,我得到了成功的 200 响应,如下所示:

    61.93.195.138 - - [29/Oct/2015:16:12:23 +0800] "GET /emt-admin/ HTTP/1.1" 200 2244
    61.93.195.138 - - [29/Oct/2015:16:12:23 +0800] "GET /emt-admin/css/foundation-datepicker.min.css HTTP/1.1" 200 2616
    61.93.195.138 - - [29/Oct/2015:16:12:23 +0800] "GET /emt-admin/css/normalize.css HTTP/1.1" 200 7708
    

    前进

    向前迈进,我决定直接使用 Tomcat 作为容器,而不是使用 lein ring server,以检查我在这个项目上所做的任何进一步工作都不会破坏废话。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-14
      • 2011-07-17
      • 1970-01-01
      • 2023-01-16
      • 2012-08-12
      • 1970-01-01
      • 2011-08-11
      相关资源
      最近更新 更多