2017-10-14 57 views
0

我已經設置Amazon AWS EC2實例並安裝了tomcat8和jdk 1.8。 我在我的tomcat的webapps目錄中部署了基於Spring/Hibernate的web-app war文件,到目前爲止一切正常。它的Spring Web MVC。在亞馬遜設置spring活動配置文件AWS EC2實例

但我想實現spring.active.profiles與我從未工作的現有配置。

下面是我的JPAConfig文件內容,它在本地服務器上運行良好,但不在AWS EC2。我覺得我的EC2實例存在一些錯誤配置。

@Configuration 
@EnableTransactionManagement 
@PropertySources({ 
    @PropertySource("classpath:application.properties"), 

     @PropertySource("classpath:application-${spring.profiles.active}.properties"), 
     @PropertySource("classpath:api.properties"), 
     @PropertySource("classpath:mailer.properties") }) 
    public class JPAConfiguration { 

     @Autowired 
     private Environment environment; 

    //rest or codes  

如果我評論@PropertySource("classpath:application-${spring.profiles.active}.properties"),線接工作的事情在EC2上不錯,但它拿起出於顯而易見的原因application.properties文件內容。當我取消註釋時,我的EC2網址返回404找不到。

請執行spring.active.profiles的EC2實例功能的幫助,使我的EC2實例使用我application-prod.properties文件

此外,請注意,對於一些未知的原因,我看不到任何其他目錄,除了「

:web應用」在我tomcat8目錄

+0

我假設你使用的是純彈簧,而不是彈簧靴,因爲你沒有提到它。 你如何設置'spring.profiles.active'屬性? –

+0

Spring的web-MVC正在使用 – sumit

+0

在我的本地服務器,使用maven和這個配置' \t \t \t \t org.apache.tomcat.maven \t \t \t \t tomcat7 - Maven的插件 \t \t \t 2,\t 2。2 \t \t \t \t <結構> \t \t \t \t \t /DMS-幅 \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 本地 \t \t \t \t \t \t \t \t \t \t \t \t' – sumit

回答

0

在戰爭中打包的web.xml的EC2實例中部署一個神器設置活動的配置文件(S),即

<context-param> 
    <param-name>spring.profiles.active</param-name> 
    <param-value>prod</param-value> 
</context-param> 

或使用註釋等見 https://www.mkyong.com/spring/spring-profiles-example/ 如果你的Tomcat是隻服此應用程序(或prod那些你也可以通過-Dspring.profiles.active=prod給JVM,即從CATALINA_OPTS的環境變量,我猜。

如果您的web應用程序是唯一託管在該tomcat上的應用程序,請考慮使用Spring Boot並將該應用程序打包爲一個胖罐子。