目录

1.首先可能是springboot静态资源访问不到

2.下面是整和mybatis的时候mapper 文件产生的问题,不映射的问题,检查一下方面,如果还出现错误,我就无能为力了

1.首先你的mapper.xml 的namespace 一定要对应到类 ,我写是时候对应到包,我就错了,好气气

2.@MapperScan("com.example.demo.mapper")记得加上这个 ,@mapper记得也要加上,

3.一定要指定一下mapper 的路径

4,。如果还不行的话,加上这个东西,在pom 文件下

5.检查一下依赖

3.springboot 中test测试类自动注入进不来的问题:


1.首先可能是springboot静态资源访问不到

这个springboot 2.0以上出现的问题,拦截器会拦截静态资源,

在自动注入的时候,覆盖了路径,需要重写

package com.ak.springboot02.config;import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;@Configuration
public class MyMvcConfig extends WebMvcConfigurationSupport {protected void addViewControllers(ViewControllerRegistry registry) {registry.addViewController("/").setViewName("login");}@Overrideprotected void addResourceHandlers(ResourceHandlerRegistry registry) {registry.addResourceHandler("/**").addResourceLocations("classpath:/resources/").addResourceLocations("classpath:/static/").addResourceLocations("classpath:/public/");super.addResourceHandlers(registry);}}

2.下面是整和mybatis的时候mapper 文件产生的问题,不映射的问题,检查一下方面,如果还出现错误,我就无能为力了

映射产生的问题

1.首先你的mapper.xml 的namespace 一定要对应到类 ,我写是时候对应到包,我就错了,好气气

然后呢你的xml 文件要放在 包下面扫描的时候就不会出现问题

2.@MapperScan("com.example.demo.mapper")记得加上这个 ,@mapper记得也要加上,

package com.example.demo;import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;@SpringBootApplication
@MapperScan("com.example.demo.mapper")
public class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}}

3.一定要指定一下mapper 的路径

mybatis.mapper-locations=classpath*:com/example/demo/mapper/*.xml

4,。如果还不行的话,加上这个东西,在pom 文件下

 <build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins><resources><resource><directory>src/main/resources</directory></resource><resource><directory>src/main/java</directory><filtering>true</filtering><includes><include>**/*.xml</include></includes></resource></resources></build>

5.检查一下依赖

<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.webjars</groupId><artifactId>jquery</artifactId><version>3.4.1</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.thymeleaf</groupId><artifactId>thymeleaf-spring5</artifactId></dependency><dependency><groupId>org.thymeleaf.extras</groupId><artifactId>thymeleaf-extras-java8time</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><scope>runtime</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></dependency><dependency><groupId>org.springframework.data</groupId><artifactId>spring-data-jdbc</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId></dependency></dependencies>

3.springboot 中test测试类自动注入进不来的问题:

@RunWith(SpringRunner.class)
@SpringBootTest
public class Springboot02ApplicationTests {@AutowiredDataSource dataSource;@Autowiredint k1;@Testpublic void contextLoads() throws Exception{System.out.println(k1);
//        System.out.println(dataSource.getClass());
//
//        Connection connection=dataSource.getConnection();
//
//
//        System.out.println(connection);
//
//        connection.close();}}

上面一直报错 ,说自动注入不进来?

package com.test1.demo1;import com.example.demo.DemoApplication;
import com.example.demo.mapper.StudentMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;import javax.sql.DataSource;@RunWith(SpringRunner.class)
@SpringBootTest(classes = DemoApplication.class)
public class Demo1ApplicationTests {@Autowiredprivate StudentMapper studentMapper;@Testpublic void contextLoads() {System.out.println(studentMapper.getStudentBySno(1));}}

这样子就好了,

修改

@SpringBootTest(classes = DemoApplication.class)

这样子就好了。

以上就是昨天学习springboot 出现的一系列问题,今天继续写哈哈。

遨游在报错的海洋中

学习 springboot 中出现的问题相关推荐

  1. springboot中DataSource数据源实例产生时机及所需环境

    今天学习springboot中数据源配置时想到一些问题: 仅配置mysql的username.password.url时,springboot会默认使用连接池管理数据连接源吗? 为了解惑,直接在当前项 ...

  2. SpringBoot学习笔记(4)----SpringBoot中freemarker、thymeleaf的使用

    1. freemarker引擎的使用 如果你使用的是idea或者eclipse中安装了sts插件,那么在新建项目时就可以直接指定试图模板 如图: 勾选freeMarker,此时springboot项目 ...

  3. SpringBoot学习笔记(9)----SpringBoot中使用关系型数据库以及事务处理

    在实际的运用开发中,跟数据库之间的交互是必不可少的,SpringBoot也提供了两种跟数据库交互的方式. 1. 使用JdbcTemplate 在SpringBoot中提供了JdbcTemplate模板 ...

  4. 【学习笔记】springBoot中获取sping管理的bean

    文章目录 一.使用场景 二.springBoot中获取sping管理的bean 2.1 生成工具类SpringContextUtil 2.2 使用工具类SpringContextUtil 2.3 注意 ...

  5. springboot yml怎么建常量_【Java】SpringBoot 中从application.yml中获取自定义常量

    由于这里我想通过java连接linux,connection连接需要host.port.username.password及其他路径等等.不想每次修改的时候都去改源文件,所以想写在applicatio ...

  6. springboot处理参数再转发请求_SpringBoot图文教程6—SpringBoot中过滤器的使用

    有天上飞的概念,就要有落地的实现 概念十遍不如代码一遍,朋友,希望你把文中所有的代码案例都敲一遍 先赞后看,养成习惯 SpringBoot 图文系列教程技术大纲 SpringBoot 图文教程系列文章 ...

  7. @transaction使自定义注解失效_【完美】SpringBoot中使用注解来实现 Redis 分布式锁...

    一.业务背景 有些业务请求,属于耗时操作,需要加锁,防止后续的并发操作,同时对数据库的数据进行操作,需要避免对之前的业务造成影响. 二.分析流程 使用 Redis 作为分布式锁,将锁的状态放到 Red ...

  8. Springboot中的缓存Cache和CacheManager原理介绍

    一.背景理解 什么是缓存,为什么要用缓存? 程序运行中,在内存保持一定时间不变的数据就是缓存.简单到写一个Map,里面放着一些key,value数据,就已经是个缓存了.所以缓存并不是什么高大上的技术, ...

  9. 在springboot中使用springsecurity实现安全控制

    SpringSecurity官方文档 我们在编写web应用时经常要对一些页面做安全控制,比如:对于没有访问权限的用户需要转到登录表单页面.要实现访问控制方法的多种多样,可以通过AOP.拦截器实现,也可 ...

最新文章

  1. 产品策划三:App启动页的策划方案
  2. 计算任何一天是星期几的几种算法
  3. 单调队列优化的背包问题
  4. isdigit函数python_Python判断字符串是否为数字的方法isdecimal 、isdigit、isnumeric及坑...
  5. pipreqs 组件
  6. js中出现missing ) after argument list
  7. 使用Emit动态调用方法(技术原型)
  8. 爬取B站弹幕并生成HTML格式的词云图
  9. 七牛云 PHP SDK服务器鉴权失败!参数解释
  10. sci二区计算机类有哪些期刊,二区材料类sci期刊有哪些
  11. 用参数方程绘制椭球体
  12. Android app 启动优化
  13. 将腾讯云对象存储挂载到云服务器
  14. tomcat启动后出现乱码解决
  15. 了解利用API接口通过网格策略的增长模式
  16. Python Java 滑块识别-通杀滑块
  17. 降成本利器——SRM之电子招投标
  18. 计算机联锁验证实训报告心得,计算机实训心得体会(通用5篇)
  19. 覆盖vue.js样式_使用Vue.js和Cloudinary在化身上覆盖眼镜/面罩
  20. python机器人编程——四轴UARM机械臂的运动控制(逆解)原理及python实现(上)

热门文章

  1. Emacs进阶之选择当前word/line
  2. 高通msm8996配置wlan0 Mac地址
  3. emacs for Mac命令
  4. Clojure 学习入门(16)- 正则表达式
  5. springboot之idea多模块
  6. 人脸方向学习(十六):Face Detection-BlazeFace解读
  7. jsp和mysql的乱码问题_jsp和servlet操作mysql中文乱码问题的解决办法
  8. boot入门思想 spring_SpringBoot基础入门
  9. arm b bl 地址无关码_海边同居有甜有虐,又一部BL日剧来了
  10. The application could not be installed: INSTALL_FAILED_INSUFFICIENT_STORAGE