小编Rip*_*man的帖子

如何在不依赖数据库的情况下启动spring-boot应用程序?

我正在为我的应用程序使用"Spring-boot + Hibernate4 + mysql".作为其中的一部分,我有一个要求,即使数据库关闭,我的sprint-boot应用程序应该能够启动.目前,当我尝试在没有DB启动的情况下启动Spring启动应用程序时,它会给出以下异常.

我研究了很多,发现这个例外与hibernate.temp.use_jdbc_metadata_defaults财产有关.

我尝试在spring boot的"application.yml"中设置它,但是这个属性的值没有在运行时反映出来.

异常堆栈跟踪:

2014-05-25 04:09:43.193  INFO 59755 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
2014-05-25 04:09:43.250  WARN 59755 --- [           main] o.h.e.jdbc.internal.JdbcServicesImpl     : HHH000342: Could not obtain connection to query metadata : Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
2014-05-25 04:09:43.263  INFO 59755 --- [           main] o.apache.catalina.core.StandardService   : Stopping service Tomcat …
Run Code Online (Sandbox Code Playgroud)

mysql spring jpa hibernate-4.x spring-boot

28
推荐指数
3
解决办法
3万
查看次数

ComponentScan excludeFilters在Spring 4.0.6.RELEASE中不起作用

我有一个类,我想在组件扫描时排除.我使用下面的代码来做到这一点,但似乎没有工作,虽然一切似乎都是正确的

@ComponentScan(basePackages = { "common", "adapter", "admin"}, excludeFilters = { @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = ServiceImpl.class) })
Run Code Online (Sandbox Code Playgroud)

实际上我想要有"ServiceImpl"类,它实现了"服务"接口,正在我的其余api逻辑中使用,在进行api的集成测试时,我想要排除这个实现并加载模拟的实现.但这似乎并没有发生,因为即使使用上面我得到以下错误

No qualifying bean of type [admin.Service] is defined: expected single matching bean but found 2: ServiceMockImpl,ServiceImpl
Run Code Online (Sandbox Code Playgroud)

我花了太多时间在这上面但没有任何作用.

任何帮助表示赞赏.

java spring unit-testing dependency-injection

12
推荐指数
1
解决办法
2万
查看次数

在Spring-Boot中,我们如何在同一个项目中连接两个数据库(Mysql数据库和MongoDB)?

我正在尝试创建一个"Spring-Boot"项目,其中我有一个要求,我想要连接到不同的数据库"MySql"和"MongoDB".

我是否需要做一些特殊的事情才能连接到两个数据库,或者spring-boot会自动计算连接到两个数据库本身.我是否还需要为"mongodb"定义数据源?

MySQL特定的"YML"文件如下所示

# Default DB parameter definitions for the URL parameters in the spring.datasource.url property below
database:
  host: localhost
  port: 3306
  schema: subscriptions
  username: root
  password: root
  autoconnect:
    maxReconnects: 3
    initialTimeout: 2
  timeout:
    connectTimeout: 0
    socketTimeout: 0
  failover:
    host: localhost 
    port: 3306
    queriesBeforeRetryMaster: 50
    secondsBeforeRetryMaster: 30
  properties: useTimezone=true&serverTimezone=UTC&useLegacyDatetimeCode=false&failOverReadOnly=false&autoReconnect=true&maxReconnects=${database.autoconnect.maxReconnects}&initialTimeout=${database.autoconnect.initialTimeout}&connectTimeout=${database.timeout.connectTimeout}&socketTimeout=${database.timeout.socketTimeout}&queriesBeforeRetryMaster=${database.failover.queriesBeforeRetryMaster}&secondsBeforeRetryMaster=${database.failover.secondsBeforeRetryMaster}

spring:
  datasource:
    driverClassName: com.mysql.jdbc.Driver
    url: jdbc:mysql://${database.host}:${database.port},${database.failover.host}:${database.failover.port}/${database.schema}?${database.properties}
    username: ${database.username}
    password: ${database.password}
    continueOnError: true
    initialize: false
    initialSize: 0
    timeBetweenEvictionRunsMillis: 5000
    minEvictableIdleTimeMillis: 5000
    removeAbandonedTimeout: 60
    removeAbandoned: true
    minIdle: 0

  jpa:
    show-sql: true
    hibernate:
      ddl-auto: …
Run Code Online (Sandbox Code Playgroud)

java mysql spring mongodb spring-boot

7
推荐指数
1
解决办法
4429
查看次数