我已经设置了Amazon AWS EC2实例并安装了tomcat8和jdk 1.8。 我已经在tomcat的webapps目录中部署了基于Spring / Hibernate的web-app war文件,到目前为止一切正常。它的Spring Web MVC。
但我想用现有的配置实现 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 URL返回404 NOT not found。
请帮助在EC2实例上实现spring.active.profiles功能,以便我的EC2实例使用我的application-prod.properties
文件
此外,请注意,由于某些未知原因,我无法在tomcat8的目录中看到除“webapps”之外的任何其他目录
答案 0 :(得分:0)
在EC2实例中部署的工件上设置活动配置文件,即 在战争中打包的web.xml上:
web.xml
<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
env var我猜。
如果您的webapp是唯一一个托管在该tomcat上的,请考虑使用Spring Boot并将webapp打包为胖罐。