首页 > 解决方案 > 使用开发配置或测试配置运行 Spring Boot 应用程序

问题描述

我有一些多环境配置。

application.yml就像_

spring:
  profiles:
    active: @profileActive@

application-dev.yml就像_

server:
  port: 8085

  spring:
    application:
      name: xxxx-info
    datasource:
      name: xxx-db
      type: com.alibaba.druid.pool.DruidDataSource
      url: jdbc:mysql://192.168.1.14:3306/xxx
      username: root
      password: *******
      driver-class-name: com.mysql.jdbc.Driver
      minIdle: 1
      maxActive: 8
      initialSize : 1
      testWhileIdle: true

  mybatis:
    typeAliasesPackage: com.xxx.commons.common.entity
    mapperLocations: classpath:mybatis/*.xml

application-test.yml是一样的application-dev.yml

Application.java就好像

@EnableDiscoveryClient
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
@MapperScan("com.xxx.ggg.client.dao")
public class ClientInfoApplication {
    private static final Logger LOGGER = LoggerFactory.getLogger(ClientInfoApplication.class);

    public static void main(String[] args) {
        SpringApplication.run(ClientInfoApplication.class, args);
    }

}

然后我在 IntelliJ 中运行 spring boot 应用程序春季运行配置

这是问题所在。使用 application-test.yml 运行 spring boot 应用程序成功,但使用 application-dev.yml 不成功。

日志就像

2018-12-17 14:27:23.497 [main][INFO]com.xxx.ggg.client.ClientInfoApplication[597]: The following profiles are active: dev
2018-12-17 14:27:24.490 [main][INFO]org.apache.coyote.http11.Http11NioProtocol[180]: Initializing ProtocolHandler ["http-nio-8080"]
2018-12-17 14:27:24.499 [main][INFO]org.apache.catalina.core.StandardService[180]: Starting service [Tomcat]
2018-12-17 14:27:24.500 [main][INFO]org.apache.catalina.core.StandardEngine[180]: Starting Servlet Engine: Apache Tomcat/8.5.31
2018-12-17 14:27:24.644 [localhost-startStop-1][INFO]org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/][180]: Initializing Spring embedded WebApplicationContext
2018-12-17 14:27:24.956 [main][WARN]org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext[551]: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clientInfoRunner': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tagService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'tagInfoDao' defined in file [D:\projects\ggg\client-info\target\classes\com\xxx\ggg\client\dao\TagInfoDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (the profiles "dev" are currently active).
2018-12-17 14:27:24.956 [main][INFO]org.apache.catalina.core.StandardService[180]: Stopping service [Tomcat]
2018-12-17 14:27:24.981 [main][ERROR]org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter[42]: 

***************************
APPLICATION FAILED TO START
***************************

Description:

Cannot determine embedded database driver class for database type NONE

Action:

If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (the profiles "dev" are currently active).

标签: spring-bootintellij-ideaspring-profiles

解决方案


推荐阅读