春季启动:具有特定配置文件的Maven软件包

时间:2020-04-14 20:45:31

标签: java spring spring-boot maven deployment

目标是拥有devprod环境。要使本地运行使用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。

我在做什么错了?

0 个答案:

没有答案