构建Spring项目以在另一个系统上运行 [英] Build Spring project for run on another system
问题描述
我在自己的本地系统上成功创建了一个Spring Boot项目.我想构建一个jar文件,以便可以将其安装在远程服务器上.因此我必须配置远程服务器的服务器地址和mySql地址,但是我无法构建它并且有很多错误,而且它们都很好,导致我的系统无法看到远程服务器地址和数据库.
I Successfully create a spring boot project on my own local system. I want to build a jar file so I can install it on remote server. so I had to configure server address and mySql address of remote server but I can not Build and it have many errors, and they all right cause my system can not see the remote server address and database.
这是我的.properties文件:
this is my .properties file:
spring.datasource.url=jdbc:mysql://localhost:8081/aths
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto=create
server.address=192.168.24.250
server.port=8080
如何处理它以便在其他配置上运行? (另一个IP,数据源和...) 我做对了吗?谢谢
how can handle it for running on another configurations? ( another IP, datasource, and ...) Am I doing it right or not? thanks
推荐答案
您可以在此处使用spring配置文件:
使用application-{profile}.properties
格式为不同的配置文件创建不同的属性文件,例如用于开发的application-dev.properties
和用于生产的application-prod.properties
将配置文件特定的配置放入其中.然后,当您运行Spring Boot应用程序时,请使用SPRING_PROFILES_ACTIVE环境变量或spring.profiles.active系统属性来激活您想要的配置文件.
You can use spring profiles here :
Create different property files for different profiles using application-{profile}.properties
format, e.g. application-dev.properties
for dev, and application-prod.properties
for production put your profile specific configurations in them. Then when you're running the spring boot application, activate your intended profile using the SPRING_PROFILES_ACTIVE environment variable or spring.profiles.active system property.
最后,您将使用以下命令运行jar文件
java -jar -Dspring.profiles.active=prod application.jar
and at the end, you will run your jar file with command
java -jar -Dspring.profiles.active=prod application.jar
这篇关于构建Spring项目以在另一个系统上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!