Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.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
将SpringBoot与Mysql连接时出错_Mysql_Spring Boot - Fatal编程技术网

将SpringBoot与Mysql连接时出错

将SpringBoot与Mysql连接时出错,mysql,spring-boot,Mysql,Spring Boot,我正试图用SpringBoot连接到MySQL数据库,但出现了一个错误 import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.*; import java.sql.*;

我正试图用SpringBoot连接到MySQL数据库,但出现了一个错误

    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    import org.springframework.web.bind.annotation.*;
    import java.sql.*;

    @RestController
    @RequestMapping
    public class miController {

        private static String driver = "com.mysql.jdbc.Driver";
        private static String server = "jdbc:mysql://localhost/test";
        private static Connection conexion = null;

        miController(){
            conectar();
        }


        private void conectar() {
             try {
                 Class.forName(driver);
                 conexion = DriverManager.getConnection(server, "Yo", "pass");
             } catch (Exception e) {
                 System.out.println("Error: Imposible realizar la conexion a BD.");
                 e.printStackTrace();
             }

        }

    @RequestMapping(value = "/hola", method = RequestMethod.GET)
        public @ResponseBody String hola() {
            return "Hola mundo2!!  " ;
        }

    }
应用程序启动时给出的错误代码为:

Thu Jun 28 17:24:42 CEST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Error: Imposible realizar la conexion a BD.
java.sql.SQLException: Unable to load authentication plugin 'caching_sha2_password'.
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:869)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:865)
    at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1746)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1226)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2188)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2219)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2014)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:776)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
Thu Jun 28 17:24:42 CEST 2018警告:不建议在没有服务器身份验证的情况下建立SSL连接。根据MySQL 5.5.45+、5.6.26+和5.7.6+的要求,如果未设置explicit选项,默认情况下必须建立SSL连接。为了符合不使用SSL的现有应用程序,verifyServerCertificate属性设置为“false”。您需要通过设置useSSL=false显式禁用SSL,或者设置useSSL=true并为服务器证书验证提供信任库。
错误:不可能实现一个BD。
java.sql.SQLException:无法加载身份验证插件“缓存\u sha2\u密码”。
位于com.mysql.jdbc.SQLError.createSQLException(SQLError.java:869)
位于com.mysql.jdbc.SQLError.createSQLException(SQLError.java:865)
在com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication上(MysqlIO.java:1746)
位于com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1226)
位于com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2188)
位于com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2219)
com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2014)
位于com.mysql.jdbc.ConnectionImpl(ConnectionImpl.java:776)
位于com.mysql.jdbc.JDBC4Connection(JDBC4Connection.java:47)

这是我第一个使用SpringBoot的应用程序,我不明白为什么我在连接mysql时出错。。。我想我在SSL上看到了一些东西,但我不明白。。。Ty

Mysql应该在SpringBoot的application.properties文件中配置。这就是SpringBoot的魅力所在

配置示例如下所示:

#Mysql connection configurations
spring.datasource.url = jdbc:mysql://localhost:3306/yourDatabaseName?useSSL=false
spring.datasource.username = yourDbUserName
spring.datasource.password = yourDbPassword
spring.datasource.driver-class-name = com.mysql.cj.jdbc.Driver

获取连接的方式远远不是引导哲学。你使用什么环境,servlet容器,JEE?所有人都有这个问题解决哲学。。。我是新的靴子,我不知道什么…我的连接是与。。。DriverManager.getConnection。我不知道你为什么这么做?private void conectar(){try{Class.forName(driver);conexion=DriverManager.getConnection(server,“Yo”,“pass”);}catch(异常e){System.out.println(“错误:不可能的实现者la conexion a BD.”;e.printStackTrace();}尝试使用“spring启动程序数据jpa”