我的 springboot 应用程序在 DEV 环境中运行良好,现在我想隔离 DEV 和 PROD 环境,以便它获取各自的代码。
我确实浏览了一些教程并获得了一些线索,但无法就如何分离出 PROD 部分得出结论。
这个应用程序基本上在从角度应用程序提交表单时向 gmail 发送电子邮件。这就是我到目前为止在 springboot 应用程序上所做的,以将其隔离。
我已经根据实际文件创建application-dev.properties并添加了两个单独的 gmail 帐户,一个用于 DEV,一个用于 PROD。并将配置文件添加到 POM.xmlapplication-prod.propertiesapplication.properties
有关如何从现有代码创建 PROD 环境的任何帮助都将非常有帮助。我对 springboot 以及如何针对不同环境进行分析还很陌生。
application.properties 文件(实际文件)是:
server.port=8084
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=test1@gmail.com
spring.mail.password=xxxxxxxxxxxxx
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
Run Code Online (Sandbox Code Playgroud)
新的 application-dev.properties 文件
server.port=8084
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=test1@gmail.com
spring.mail.password=xxxxxxxxxxxxxxx
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.profiles.active=@activatedProperties@
Run Code Online (Sandbox Code Playgroud)
新的 application-prod.properties 文件
server.port=8085
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=test2@gmail.com
spring.mail.password=xxxxxxxxxxxxxxx
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
Run Code Online (Sandbox Code Playgroud)
POM.xml 文件
<profile>
<id>dev</id>
<properties>
<activatedProperties>dev</activatedProperties>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>prod</id>
<properties>
<activatedProperties>prod</activatedProperties>
</properties>
</profile>
Run Code Online (Sandbox Code Playgroud)
主要的EmailClientHmwApplication.java文件如下: …