2017-04-27 169 views
2

我有這個配置在我application.ymlserver.session.timeout在部署到Tomcat作爲戰爭不使用

server: 
    contextPath: /appname 
    session: 
     timeout: 7200 # 2 hours in seconds 

,當我在IntelliJ IDEA的運行也能正常工作,但當我將構建.war文件部署到tomcat實例時,這會被忽略。這是一個錯誤還是不能像這樣工作?

此外,我似乎無法找到什麼可以寫在application.yml規範。任何人都知道在哪裏可以找到?

application.groovy配置文件怎麼樣?似乎無法找到這個規範?

我的環境:

  • 的Grails版本:3.2.8
  • 搖籃版本:3.4.1
  • IntelliJ IDEA的版本:2017年1月2日
  • Tomcat的版本:8.0.26 JDK版本:1.8.0_45
+0

http://stackoverflow.com/questions/43215649/grails-3 -session-timeout-not-working-when-deployed-to-tomcat似乎是一個類似的問題。基本上application.yml不確定一個規範,取決於使用的插件等等。簡而言之,appilcation.groovy可以創建在與application.yml相同的路徑/文件夾中。你的應用程序將會讀取這兩個文件,你可以用yml風格或者更老的.groovy風格來配置它,它是'some.element.key = value' – Vahid

+0

這確實是同樣的問題。我會測試它是否有效,如果我將它移動到.groovy文件。我仍然認爲這是一個錯誤。對此有何想法? – user3728821

+0

該頁面上的答案表明你必須爲其配置tomcat - 所以不要懷疑它是一個錯誤 – Vahid

回答

0

當您將Grails 3應用程序部署到獨立的tomcat應用程序時,您不應該使用springboot server.session.timeout配置屬性。它只適用於嵌入式服務器。

Spring boots - sever.session.timeout - Embedded Server configuration

配置在SpringBoot應用程序會話超時(Grails的3應用程序是建立在SpringBoot應用程序的頂部)部署到一個獨立的Tomcat,你有兩個選擇:

A)超時每個應用都部署在該Tomcat實例中。

你可以在Tomcat的配置文件直接編輯會話超時:

$TOMCAT_HOME/conf/web.xml 

查找出該塊:

<!-- ==================== Default Session Configuration ================= --> 
<!-- You can set the default session timeout (in minutes) for all newly --> 
<!-- created sessions by modifying the value below. --> 

<session-config> 
    <session-timeout>30</session-timeout> 
</session-config> 

B)您可以添加一個web.xml文件的Grails 3應用程序,每個應用程序需要超時。

創建路徑文件 '的src /主/ web應用/ WEB-INF/web.xml文件' 與內容:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 
<session-config> 
    <session-timeout>30</session-timeout> 
</session-config> 
</web-app>