2017-10-14 114 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并将该应用程序打包为一个胖罐子。