Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring Boot Cloug配置客户端无法自动连线_Java_Spring Boot_Jdbc_Spring Cloud Config - Fatal编程技术网

Java Spring Boot Cloug配置客户端无法自动连线

Java Spring Boot Cloug配置客户端无法自动连线,java,spring-boot,jdbc,spring-cloud-config,Java,Spring Boot,Jdbc,Spring Cloud Config,我在这里遵循了一个教程: 我无法从数据库自动连接密钥 @RefreshScope @RestController public class MainController { @Value("${key}") private String sql; @Autowired private DataSource dataSource; @RequestMapping("/showConfig") @ResponseBody public String showConfig() { S

我在这里遵循了一个教程:

我无法从数据库自动连接密钥

 @RefreshScope
 @RestController
 public class MainController {
@Value("${key}")
private String sql;

@Autowired
private DataSource dataSource;

@RequestMapping("/showConfig")
@ResponseBody
public String showConfig() {
    String configInfo = "sql key-value pair" + sql;
return configInfo;
}
客户端bootstrap.properties:

spring.application.name=config-client

# This is the default:
spring.cloud.config.uri=http://localhost:8888
management.security.enabled=false

spring.cloud.config.label=master
spring.cloud.config.profile=test
server.port=7777
服务器属性

server.port=8888
spring.datasource.url=jdbc:mariadb://localhost:3306/noob? 
createDatabaseIfNotExist=true
spring.datasource.username=root
spring.datasource.password=abc123
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
spring.datasource.platform= mysql
spring.datasource.hikari.connection-timeout=5000
spring.datasource.hikari.maximum-pool-size=10

spring.profiles.active= jdbc

spring.jpa.hibernate.ddl-auto=create-drop
spring.cloud.config.server.default-profile=production
spring.cloud.config.server.default-label=latest

spring.cloud.config.server.jdbc.sql=SELECT `key`, `value` FROM `properties` 
WHERE `application`=? AND `profile`=? AND `label`=?;
spring.cloud.config.server.jdbc.order=0
我在我的noob数据库中制作了以下表格:

CREATE TABLE `properties` (
  `application` varchar(200) DEFAULT NULL,
  `profile` varchar(200) DEFAULT NULL,
  `label` varchar(200) DEFAULT NULL,
  `key` varchar(200) DEFAULT NULL,
  `value` varchar(200) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1

INSERT INTO `properties` (`key`, `value`, `application`, `profile`, 
`label`)
VALUES ('datasource-driver-class- 
name','MyDriverClass','appplication1','production','latest');
org.springframework.beans.factory.BeanCreationException:创建名为“scopedTarget.mainController”的bean时出错:自动关联依赖项的注入失败;嵌套异常为java.lang.IllegalArgumentException:无法解析值“${
key
}”中的占位符“
key
” 在org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:380)~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE] 在
... 在本教程之后省略了28个公共帧,并且使用提供的输入,您可以通过以下方式获得一些
@Value

@Value("${datasource-driver-class-name}")
private transient String driverClassName;

我接受了你的建议。我相信它应该会起作用。我希望我的结果是我的DriverClass,但我得到了另一个错误。“com.example.demo.MainController中的Field dataSource需要一个类型为'javax.sql.dataSource'的bean,但找不到该bean。”


…然后,您使用“maria”,在教程中使用的是“mysql”db,请根据maven依赖关系调整:

pom.xml:


org.mariadb.jdbc
mariadb java客户端

在教程之后,通过提供的输入,您可以通过以下方式获得一些
@Value

@Value("${datasource-driver-class-name}")
private transient String driverClassName;

我接受了你的建议。我相信它应该会起作用。我希望我的结果是我的DriverClass,但我得到了另一个错误。“com.example.demo.MainController中的Field dataSource需要一个类型为'javax.sql.dataSource'的bean,但找不到该bean。”


…然后,您使用“maria”,在教程中使用的是“mysql”db,请根据maven依赖关系调整:

pom.xml:


org.mariadb.jdbc
mariadb java客户端

你确定key@Value(${
key
})应该用反引号括起来吗?如果你遵循了教程,并且使用了底层数据,那么唯一的
@Value
,我希望是:
${datasource driver class name}
,我希望是
“MyDriverClass”
!?你应该把后背去掉-quotes@xerx593我接受了你的建议。我相信它应该会起作用。我希望我的结果是我的DriverClass,但我得到了另一个错误。“com.example.demo.MainController中的字段数据源需要一个找不到的'javax.sql.dataSource'类型的bean。”我认为这是一个进步。啊,好(小进步)!nxt问题:在教程中,他使用“mysql”db,您使用“maria”…我知道它是“同一个家族”,但驱动程序类(名称)不同!(在另一个jar/dependency中)…->pom.xml(查找mysql替换为正确的驱动程序依赖项…google!)您确定key@Value(${code>key})应该用反引号括起来吗?如果您遵循教程,并且使用底层数据,我期望的唯一
@Value
,是:
${datasource driver class name}
,,我希望它是
“MyDriverClass”
…:)!?你应该把后背去掉-quotes@xerx593我接受了你的建议。我相信它应该会起作用。我希望我的结果是我的DriverClass,但我得到了另一个错误。“com.example.demo.MainController中的字段数据源需要一个找不到的'javax.sql.dataSource'类型的bean。”我认为这是一个进步。啊,好(小进步)!nxt问题:在教程中,他使用“mysql”db,您使用“maria”…我知道它是“同一个家族”,但驱动程序类(名称)不同!(在另一个jar/依赖项中)…->pom.xml(找到mysql替换为正确的驱动程序依赖项…google!)