spring云配置服务器jdbc返回重复的propertsources

yacmzcpb  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(236)

我使用springcloudconfig服务器从mysql表读取config,它返回重复的属性源。
代码如下:

@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
    }
}

应用程序.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",
      "source": {
        "user.role": "dev",
        "user.tech": "scala"
      }
    }
  ]
}

正如你所看到的,有多个重复的属性源,我试过很多方法,比如更改drver等等,但没有任何帮助。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题