Spring-Cloud ConfigServer JDBC 返回重复的属性源

问题描述

我正在使用 spring cloud 配置服务器从 MysqL 表中读取配置,它返回重复的属性源。

代码如下:

@SpringBootApplication
@Enableconfigserver
@Import(JdbcEnvironmentRepository::class)
class configserverApplication

fun main(args: Array<String>) {
    runApplication<configserverApplication>(*args)
}


@Configuration
@ConfigurationProperties(prefix = "spring.datasource")
class DatabaseConfig {

    var url: String = ""
    var username: String = ""
    var password: String = ""
    var driverClassName: String = ""

    @Bean
    @Primary
    fun dataSource(): DataSource {
        val dataSource = SimpleDriverDataSource()
        dataSource.setDriverClass(Class.forName(driverClassName) as Class<out java.sql.Driver>)
        dataSource.url = url
        dataSource.username = username
        dataSource.password = password
        return dataSource
    }
}

application.yml

logging:
  level:
    root: trace


server:
  port: 8888
spring:
  cloud:
    config:
      server:
        bootstrap: true
        jdbc:
          sql: select prop,value from properties where APPLICATION=? and PROFILE=? and LABEL=?
  datasource:
    url: jdbc:MysqL://localhost:3306/configprops?useSSL=false
    username: user
    password: pass
    driverClassName: com.MysqL.jdbc.Driver
  profiles:
    active:
      - jdbc

表格内容

+-------------+---------+-------+-----------+---------+
| application | profile | label | prop      | value   |
+-------------+---------+-------+-----------+---------+
| viki        | dev     | roles | user.role | dev     |
| viki        | dev     | roles | user.tech | scala   |
| properties  | default | viki  | user.role | manager |
+-------------+---------+-------+-----------+---------+

现在当我点击 http://localhost:8888/viki/dev/roles

我得到以下输出

{
  "name": "viki","profiles": [
    "dev"
  ],"label": "roles","version": null,"state": null,"propertySources": [
    {
      "name": "viki-dev","source": {
        "user.role": "dev","user.tech": "scala"
      }
    },{
      "name": "viki-dev","user.tech": "scala"
      }
    }
  ]
}

如您所见,有多个重复的属性源,我尝试了很多方法,例如更改驱动程序等,但没有任何帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)