初探springboot的荆棘之路

My courage always rises with every attempt to intimidate me.

上面的名言紧记,自己探索着将springboot整合mybatis,遇到了很多错误,很多,每一个错误都第一次遇见,并且都是很难得,对现在的我而言!但是没有打败,还是一步步探索下去了

Action

第一个错

        属于不知道前面的路,编写的第一步就是找依赖,也就是从这里开始犯得错,springboot和spring 其中的不同也在这里看下面代码

这是spring 引入的依赖,并且我都写有注释,一目了然,但是多,别看只有仅仅3个,但是代码

向下编写,依赖也会随之增多

    <!-- mySQL -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.47</version>
    </dependency>

    <!-- MyBtais -->
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
        <version>3.5.6</version>
    </dependency>
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis-spring</artifactId>
        <version>2.0.6</version>
    </dependency>

 接下来是springboot的错

         <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.0.1</version>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-core</artifactId>
            <version>3.3.2</version>
        </dependency>

减少了一个,这里犯得错就是,倒错依赖了。感觉体现不出来

第二个错

 依赖版本问题

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.47</version>
        </dependency>

我的数据库是5.几的,然后我导了一个5.1.47,没问题吧,但是问题一大堆,而且错的很离谱

 Error creating bean with name 'employController': Unsatisfied dependency expressed through field 'employService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employServiceImpl': Injection of resource dependencies failed; nested exception is   

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employMapper' defined in file [D:\springboot狂神\springboot-03-web2\target\classes\com\sl\mapper\EmployMapper.class]: Cannot resolve reference to bean 'sqlSessionTemplate' while setting bean property 'sqlSessionTemplate'; nested exception is 

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionTemplate' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionTemplate' parameter 0; nested exception is 

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0; nested exception is 

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; 
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception;
 nested exception is java.lang.IllegalStateException: Cannot load driver class: com.mysql.cj.jdbc.Driver 	

表达一堆我的‘控制层,和实现类异常

创建名为'employServiceImpl'的bean时出错:资源依赖项注入失败;嵌套的异常

然后我去在解决方法

看到下面的解决一(不是本人解决办法,感觉不好使)

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

在启动类加入这个,但是启动类是系统创建的,应该不会少什么,所以在寻找博客,还好继续找了

发现第二个解决方法

解决二(解决)

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.22</version>
        </dependency>

版本问题,

但是当你导入这个后,接着发生第三个错误

第三个错误

java.sql.SQLException: Access denied for user ''@'localhost' (using password: YES)

这个错是今天最难改的 ,以前也是这个数据库,然后也没发现有误,然后找到这个

(无效)解决办法一

去数据库更改权限,但是我保持疑惑,使用这么久不应该权限问题啊,不可能springboot会出现权限更改

授权语句:          grant all privileges on *.* to root@'%' identified by '自己数据库的密码';

试了好多遍,还是不好使,放弃

(无效)解决办法二

更改mysql,这个最可怕,写了两个代码让位改命令,并且删掉,这个没有尝试,也不敢尝试(前提是之前写的代码,是可以正常运行的,如果是第一次,也就存在可能是电脑安装的时候造成的

(正确解决办法)解决办法三

正确的操作,也是最气的,自己刚开始的写的配置文件application.properties 中的密码和用户名

#用户名
spring.datasource.name= root
#密码
spring.datasource.password= root

更改后的

#用户名
spring.datasource.username= root
#密码
spring.datasource.password= root

是不是一下看出来了,但是第一次写,idea给的提示,(spring.datasource.name= )毫不犹豫的按下了ENTER,哈哈哈

好气啊也是这个错把我心态搞炸了

第四个错误

The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specific time zone value if you want to utilize time zone support.    

还有乱码,但是好改错

流程

1.win+R

2. 输入  cmd

3.输入 mysql -uroot -p

4.继续输入:set global time_zone='+8:00';

然后搞定,这是一个更改mysql时区的命令

这就是所以今天遇到的错误!

记录美好的一天

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值