目标是拥有dev
和prod
环境。要使本地运行使用application-dev.yml
,要部署到服务器以使用application-prod.yml
我有3个配置文件
application.yml
spring:
main:
banner-mode: off
application-dev.yml
spring:
datasource:
password: dev-user-pwd
username: dev-user
url: jdbc:mysql://localhost:3306/db
driver-class-name: com.mysql.cj.jdbc.Driver
application-prod.yml
spring:
datasource:
password: prod-user-pwd
username: prod-user
url: jdbc:mysql://localhost:3306/db
driver-class-name: com.mysql.cj.jdbc.Driver
在服务器中,我已安装maven
并尝试运行
mvn clean package -Dspring.profiles.active=prod
这是我收到的错误日志
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 10.966 s <<< FAILURE! - in com.partplug.api.ApiApplicationTests
contextLoads Time elapsed: 0.005 s <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration': Unsatisfied dependency expressed through method 'setConfigurers' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.data.web.config.SpringDataWebConfiguration': Injection of autowired dependencies failed; nested exception is java.lang.NoClassDefFoundError: org/xmlbeam/config/XMLFactoriesConfig
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.data.web.config.SpringDataWebConfiguration': Injection of autowired dependencies failed; nested exception is java.lang.NoClassDefFoundError: org/xmlbeam/config/XMLFactoriesConfig
Caused by: java.lang.NoClassDefFoundError: org/xmlbeam/config/XMLFactoriesConfig
Caused by: java.lang.ClassNotFoundException: org.xmlbeam.config.XMLFactoriesConfig
简而言之:该错误表明,未定义数据源和所有子属性。这意味着,maven打包程序不会将活动配置文件更改为prod。
我在做什么错了?