学习Spring Boot遇到的问题

1.问题:springboot新建项目的时候没有spring initializr选项
  我的是社区版的要下载spring Assistant
  解决IDEA Plugins的Marketplace搜索不到插件


  勾选上就可以搜索到了,然后重启idea

 2. 问题:idea创建springboot项目Error while fetching metadata from server ‘https://start.spring.io’ Please check URL, network and proxy settings.

 解决:

 

上图默认是http,然后加了个s就好了

3.Cannot resolve plugin org.apache.maven.plugins:maven-site-plugin:3.3

解决:pom加入依赖

<dependency>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-site-plugin</artifactId>
   <version>3.3</version>
</dependency>

 4.项目正常启动,无报错,但是访问页面404

导入依赖:

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

 5.idea社区版没有Database,安装插件Database Navigator代替

  View-Tool Windows-DB Browser打开

 6.Method does not override method from its superclass

7.Duplicate class: 'UserMapper'

写了两个,重写了

8.问题:

 

 

启动类的注解和配置文件要和文件名保持一致

 9.问题:springboot db navigator access denied for user 'localhost'@'localhost'(using password:yes)

 

 看了什么不要有空格,权限问题,加jdbc….最后把用户和密码删掉重新打一遍,就好了,555

 driver-class-name: com.mysql.cj.jdbc.Driver

而且我的版本里是不能有cj.的,不然有错误,版本问题

10.springboot社区版database navigator连接不上

 

 

中间还配置了数据库权限,然后莫名好了

GRANT ALL PRIVILEGES ON *.* TO 'localhost'@'localhost' IDENTIFIED BY 'root' WITH GRANT

OPTION;

FLUSH PRIVILEGES;

 11.Caused by: org.xml.sax.SAXParseException: 不允许有匹配 "[xX][mM][lL]" 的处理指令目标

 

 xml文件前面不能有空格

12.Cannot resolve symbol 'String' 

注意大小写….   把String写成了string

13.光标变成白色方块,所到之处代码消失

   原因:按到了insert键,再按一下就好

14.label标志for指向的id还没写就会爆红

15.问题:Error resolving template [users], template might not exist or might not be accessible by any of the configured Template

模板找不到查找资料说加注解@ResponseBody什么的,最后发现原来是我把.html文件命名成了..html文件,真坑啊

16.IDEA项目右边没有maven

点击help-find..-,输入Maven,点击Add Maven Projects,最后选择本项目的pom点击ok,就好啦

17.navicat [Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''ay_user' (

解决:列名和表明都要用反括号,``,键盘esc下面那个键

18. 问题:Cannot resolve plugin org.apache.maven.plugins:maven-compiler-plugin:3.1

 解决:maven的路径都是对的,还是下载失败,最后发现,是网络的问题,把maven仓库的文件都删掉重新下载就好了

19.问题:Cannot resolve plugin org.mortbay.jetty:maven-jetty-plugin:6.1.25

解决:下不了,pom输入相应格式即可下载

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>9.3.14.v20161028</version>
    <configuration>
        <webAppConfig>
            <maxFormContentSize>600000</maxFormContentSize>
            <contextPath>/file</contextPath>
        </webAppConfig>


        <scanIntervalSeconds>3</scanIntervalSeconds>
        <webAppSourceDirectory>${basedir}/webapp/</webAppSourceDirectory>
        <stopPort>9998</stopPort>
        <stopKey>stop</stopKey>
        <jettyConfig/>
        <systemProperties>
            <systemProperty>
                <name>UrlEncoded</name>
                <value>GBK</value>
            </systemProperty>
        </systemProperties>
    </configuration>
</plugin>

相应位置在:D:\apache-maven-3.5.2\repository\org\apache\maven\plugins

20.debug调试

问题:Connected to the target VM, address: '127.0.0.1:54426', transport: 'socket'

 解决:打完断点之后运行没有反应,是因为运行中没有触发到打断点的位置

21.问题:ERROR com.alibaba.druid.pool.DruidDataSource: create connection error, url: jdbc:mysql://localhost:3306/sportswork?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC, errorCode 1045, state 28000 java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

解决:密码输错了,cmd登陆mysql确认一下

22.问题:springboot出现登录界面,springboot-莫名其妙的登录界面“Please sign in“

转载链接:springboot-莫名其妙的登录界面“Please sign in“_hayhead的博客-CSDN博客

spring启动类上加 @SpringBootApplication(exclude={SecurityAutoConfiguration.class})

23.问题:

Field userMapper in com.library.library.service.UserService required a bean of type 'com.library.library.mapper.UserMapper' that could not be found.
​
The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)
​
​
Action:
​
Consider defining a bean of type 'com.library.library.mapper.UserMapper' in your configuration.

解决:启动类加

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@ComponentScan(basePackages = {"com.library.library.dao"})

其中出现另一个错误,Description: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. Reason: Failed to determine suitable jdbc url

上面两个一起加就好了,效果还是没出来,我再去掉

转载链接: 启动报错Description: Failed to configure a DataSource: ‘url‘attribute is not specif: Reason:_ヾ凉秋的博客-CSDN博客

24.@Mapper,import org.apache.ibatis.annotations.Mapper;爆红

<dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.3</version>
 </dependency>

原因:缺少依赖

25.问题:[Spring boot 启动错误处理:Action: Consider the following: If you want an embedded database (H2, HSQL or Derby), please put it on the classpath. If you have database settings to be loaded from a particular.

在pom中引入了mybatis-spring-boot-starter ,Spring boot默认会加载org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration类,DataSourceAutoConfiguration类使用了@Configuration注解向spring注入了dataSource bean。因为工程中没有关于dataSource相关的配置信息,当spring创建dataSource bean因缺少相关的信息就会报错。

解决方案:

在启动类的@EnableAutoConfiguration或@SpringBootApplication中添加exclude = {DataSourceAutoConfiguration.class},排除此类的autoconfig。

转载链接:Spring boot 启动错误处理:Action: Consider the following: If you want an embedded database (H2, HSQL or Derby), please put it on the classpath. If you have database settings to be loaded from a particular... - luoluo,keep moving... - 博客园

26.问题:Unknown collation: 'utf8mb4_0900_ai_ci'

解决:utf8mb4_0900_ai_ci全部替换为utf8_general_ci utf8mb4替换为utf8 重新执行sql文件

27.问题:Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax

原因:实体类中的字段 与mysql数据库中的关键字冲突,所以抛出语法错误

解决:把dao层有冲突的字段改个名字,其它也做相应调整,我出错的是name,account

MYSQL关键字查询 : MySQL :: MySQL 5.7 Reference Manual :: 9.3 Keywords and Reserved Words

28.找不到 相应的mapper方法,服务层引用mapper层没报错

检查一下mapper里面的方法名和服务层是否一致

29.问题:This application has no explicit mapping for /error, so you are seeing this as a fallback.,html文件显示不出来,找不到相应的mapper文件

解决:我的是,把html文件放在static根路径下面就可以识别,放到下图的html就不行,还不知道原因

30.问题:### Error updating database. Cause: java.sql.SQLIntegrityConstraintViolationException: Column 'role' cannot be null ### The error may exist in file [E:\aabs\library\target\classes\mapper\UserMapper.xml] ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: insert into user(id,account,name,sex,password,role,address,phone) value (?,?,?,?,?,?,?,?) ### Cause: java.sql.SQLIntegrityConstraintViolationException: Column 'role' cannot be null ; Column 'role' cannot be null; nested exception is java.sql.SQLIntegrityConstraintViolationException: Column 'role' cannot be null

解决:数据表设置为not null,在前端页面也要设置相应的id,比如<input id="a">和数据表中的a对应的,其中a不为空

31.问题:java.lang.NullPointerException

原因:和前端页面的id值不一致

32.问题:springboot识别不了bootstrap.css文件

解决:把

<link rel="stylesheet" href="../static/bootstrap/css/bootstrap.css">

修改为:

<link rel="stylesheet" href="../bootstrap/css/bootstrap.css">

33.问题:java.sql.sqlIntegrityConstraintViolationException:

原因:主键的值重复了

34.

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值