2017-07-04 57 views
1

我是新來的春季啓動。我創建了一個使用彈簧引導的網絡應用程序。我的應用程序需要一些屬性文件來處理。在日食我做了什麼,我設置了像下面的Run configuration的路徑。如何在春季啓動webapp中設置構建路徑配置

Bellow is the screen shot 現在,當我運行應用程序時,我得到路徑上的require文件並且運行順利。 現在我想在某些服務器上部署war文件。我如何提供這個路徑給我的應用程序。

貝婁是我的項目的項目結構。和文件在這裏 強調 enter image description here

如何設置使用application.properties或任何其他方式,這樣,我沒有提供從運行配置的路徑該文件路徑,.war可以在任何服務器上部署。

更新1:這是我試過的。 創建一個customStart.bat 內容的文件是

set CATALINA_OPTS="-engine.home="/src/main/resources/" -Dlog4j.configuration=config/log4j.xml -Dlog4j.debug=true" 
call startup.bat %CATALINA_OPTS% 

但還是這樣的說法沒有設置。我怎麼做?

回答

1

從春天啓動官方文檔(這是創建自定義開機春季變量的概念的一個亮點)波紋管,你會發現一個鏈接,介紹瞭解決方案Q/A。

Spring Boot jar附帶元數​​據文件,提供所有支持的配置屬性的詳細信息 。這些文件設計爲 允許IDE開發人員提供上下文幫助和「代碼完成」,因爲 用戶正在使用application.properties或application.yml 文件。

大部分元數據文件是在 編譯時自動生成的,處理所有註釋爲 @ConfigurationProperties的項目。但是,可以手動編寫部分 元數據用於角落案例或更高級用例。

配置的元數據文件被下 META-INF /彈簧配置-metadata.json位於內側罐他們使用一個簡單的JSON格式 與下任一「基團」或「屬性」 和其他值暗示分類的項目下的 「提示」 分類:

這裏是一個元數據的配置文件的一個示例:

{"groups": [ 
    { 
     "name": "server", 
     "type": "org.springframework.boot.autoconfigure.web.ServerProperties", 
     "sourceType": "org.springframework.boot.autoconfigure.web.ServerProperties" 
    }, 
    { 
     "name": "spring.jpa.hibernate", 
     "type": "org.springframework.boot.autoconfigure.orm.jpa.JpaProperties$Hibernate", 
     "sourceType": "org.springframework.boot.autoconfigure.orm.jpa.JpaProperties", 
     "sourceMethod": "getHibernate()" 
    } 
    ... 
],"properties": [ 
    { 
     "name": "server.port", 
     "type": "java.lang.Integer", 
     "sourceType": "org.springframework.boot.autoconfigure.web.ServerProperties" 
    }, 
    { 
      "name": "spring.jpa.hibernate.ddl-auto", 
      "type": "java.lang.String", 
      "description": "DDL mode. This is actually a shortcut for the \"hibernate.hbm2ddl.auto\" property.", 
      "sourceType": "org.springframework.boot.autoconfigure.orm.jpa.JpaProperties$Hibernate" 
    } 
    ... 
],"hints": [ 
    { 
     "name": "spring.jpa.hibernate.ddl-auto", 
     "values": [ 
      { 
       "value": "none", 
       "description": "Disable DDL handling." 
      }, 
      { 
       "value": "validate", 
       "description": "Validate the schema, make no changes to the database." 
      }, 
      { 
       "value": "update", 
       "description": "Update the schema if necessary." 
      }, 
      { 
       "value": "create", 
       "description": "Create the schema and destroy previous data." 
      }, 
      { 
       "value": "create-drop", 
       "description": "Create and then destroy the schema at the end of the session." 
      } 
     ] 
    } 
]} 

每個「屬性」是用戶使用 給定值指定的配置項目。例如,server.port和server.servlet-path可能在application.properties中指定爲 ,如下所示:

server.port = 9090 server。servlet-path =/home這些「groups」的級別高於 ,它們本身並不指定值,而是爲屬性提供 上下文分組。例如,server.port和 server.servlet-path屬性是服務器組的一部分。

注:

  • 基團是音符所需
  • 「提示」是用於幫助用戶配置一個給定的屬性的其他信息。在配置spring.jpa.hibernate.ddl-auto屬性時,工具可以使用它爲none,validate,update,create和create-drop值提供一些自動完成幫助。

您可以輕鬆地生成使用 彈簧引導配置處理器罐子@ConfigurationProperties註釋 項目自己的配置元數據文件


您可以檢查這Q/A

**更多詳細信息檢查春季啓動附錄部分**

1

正如你可以添加自己的屬性,%TOMCAT_HOME%\的conf \ catalina.properties

只要把它們放在文件的末尾如下選項:

log4j.configuration =配置/的log4j.xml .....