spring与springboot
常用注解的解释,IOC和AOP的原理,框架原理,源码理解,一些组件的注册等
心诚则灵'
这个作者很懒,什么都没留下…
展开
-
The field file exceeds its maximum permitted size of 1048576 bytes
Spring Boot修改最大上传文件限制:The field file exceeds its maximum permitted size of 1048576 bytes.SpringBoot做文件上传时出现了The field file exceeds its maximum permitted size of 1048576 bytes.错误,显示文件的大小超出了允许的范围。查看了官方文档,原来Spring Boot工程嵌入的tomcat限制了请求的文件大小,这一点在Spring Boot的官方文原创 2022-04-07 11:04:41 · 469 阅读 · 0 评论 -
Java8获取List集合元素最大、最小、总和、平均值
public static void main(String[] args) { initEmp(); int sum = empList.stream().mapToInt(Employee->Employee.getAge()).sum(); int max = empList.stream().mapToInt(Employee->Employee.getAge()).max().getAsInt(); int min = .原创 2021-12-01 11:30:55 · 4194 阅读 · 0 评论 -
vscode在当前窗口同时打开两个项目的方法
vscode想在当前窗口同时打开第两个项目时,如果在vscode内直接打开第二个项目的文件夹会把第一个项目的文件夹覆盖掉,怎么解决呢?只要将文件夹添加到工作区就可以实现在当前窗口同时打开两个项目了...原创 2021-11-29 18:03:10 · 4684 阅读 · 0 评论 -
spring boot注解 对double保留两位小数
全局设置public class CustomerDoubleSerialize extends JsonSerializer { private DecimalFormat df = new DecimalFormat("0.00"); @Override public void serialize(Object o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOE原创 2021-11-18 16:33:16 · 3165 阅读 · 0 评论 -
Failed to load property source from location ‘classpath:/config/application-local.yml‘
springboot项目,采用yml配置形式的文件,报:java.lang.IllegalStateException: Failed to load property source from location 'classpath:/config/application-local.yml' at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplic.原创 2021-11-15 14:50:39 · 800 阅读 · 0 评论 -
spring boot 通过session 取数据
//先把数据存入session 中 LoginInfo loginInfo = userService.login(userName, password); request.getSession().setAttribute(Config.USER_SESSION_KEY, loginInfo);//从session 中取数据LoginInfo loginInfo = (LoginInfo) request.getSession().getAttribute(Config.USER_SE.原创 2021-11-08 15:24:15 · 702 阅读 · 0 评论 -
Could not resolve placeholder ‘spring.application.name‘ in value “${spring.application.name}“
Could not resolve placeholder ‘spring.application.name’ in value “${spring.application.name}”springboot项目启动报错,配置文件用的是application.properties。原因:application.properties文件格式不对解决办法:第一行留空,从第二行开始写配置信息...原创 2021-10-26 16:08:58 · 5582 阅读 · 0 评论 -
Cause: java.sql.SQLException: 无法转换为内部表示
框架spring jdbc 查询数据时抛出Cause: java.sql.SQLException: 无法转换为内部表示的异常原因,数据库字段是数值类型,但实体bean对应的类型是String,类型不匹配原创 2021-10-26 16:05:13 · 614 阅读 · 0 评论 -
SpringBoot项目中Service和ServiceImpl的选择
一般Spring项目中处理业务的层为Service层,称为业务层。目前常见的风格有:写法一: Service层 = Service类举个栗子:① Service类:(自动注入Dao层)@Servicepublic class RoleService { @Autowired RoleMapper roleMapper; public List<Role> roles() { return roleMapper.roles();原创 2021-10-22 17:49:42 · 6539 阅读 · 0 评论 -
java.lang.IllegalStateException: Logback configuration error detected
最近由于公司项目整合spring boot与Log4j2时,导致项目运行不起来报错原因: Logback 配置错误:报错代码:很明显分析出是Logback 配置错误解决方式: 报错路径: C:\Users\Administrator\Desktop\log\error\log_error.log 很明显我现在的管理员名字是:admin,而logback.xml文件配置中是Administrator所以导致它无法创建日志文件路径,将其需改为:C://Users/...原创 2021-10-19 17:20:07 · 13412 阅读 · 0 评论 -
导出excel时报The maximum column width for an individual cell is 255 characters
java.lang.IllegalArgumentException: The maximum column width for an individual cell is 255 characters. org.apache.poi.xssf.usermodel.XSSFSheet.setColumnWidth(XSSFSheet.java:2386) com.lemon.web.XExcelServlet.attach(XExcelServlet.java:69) com.lemon.web.X.原创 2021-10-12 16:38:33 · 646 阅读 · 0 评论 -
mybatis 执行mapper的方法时报空指针的问题
mybatis报空指针service层调用其他service层方法时报空指针根据指示定位到指定行找了很久找不到原因。配置文件,注解,依赖都是对的。最后发现被调用层的引用没有加@Autowired或者加上构造方法。...原创 2021-07-30 11:56:13 · 3235 阅读 · 1 评论 -
mybatis 中<foreach collection=“xxx“ item=“xxx“ index=“index“ open=“(“ separator=“,“ close=“)“> 参数详解
(1)collection = “” ,这个参数是 dao 层(mapper)接口方法里面传过来的集合参数,如果dao 层传的参数只有一个,这里写关键字 list(如果是数组,写 array)例子:dao 层:User getInfo(List user_ids)collection = “list”【如果有多个参数,并且使用了 @Param 注解(import org.apache.ibatis.annotations.Param),则这里要写注解里面的参数!例子: dao 层 :User原创 2021-07-02 18:00:13 · 5047 阅读 · 0 评论 -
@RequestMapping注解使用
在Spring MVC中使用@RequestMapping来映射请求,即通过它来指定控制器可以处理哪些URL请求,相当于Servlet中在web.xml中配置的映射作用一致。<servlet> <servlet-name>servletName</servlet-name> <servlet-class>ServletClass</servlet-class></servlet><servlet-mappin原创 2021-07-02 15:20:30 · 350 阅读 · 2 评论 -
SpringBoot中Required String parameter ‘××ב is not present解决方法
错误分析使用Post向接口发送json数据时显示如下错误。WARN 13392 --- [nio-8080-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved exception caused by handler execution: org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'use原创 2021-07-02 11:24:31 · 1078 阅读 · 0 评论 -
@RestController注解使用
本次介绍SpringBoot中针对http的常用注解。SpringBoot仍然秉承MVC的架构,在注解命名方面遵循此类讲究,对于负责Restful API交互的功能模块,SpingBoot采用@RestController在修饰类。@RestController@RestController = @Controller + @ResponseBody@Controller 将当前修饰的类注入SpringBoot IOC容器,使得从该类所在的项目跑起来的过程中,这个类就被实例化。当然也有语义化的作用,原创 2021-06-30 10:48:03 · 2202 阅读 · 1 评论 -
@RequestParam注解使用
作用@RequestParam:将请求参数绑定到你控制器的方法参数上(是springmvc中接收普通参数的注解)语法语法:@RequestParam(value=”参数名”,required=”true/false”,defaultValue=””) value:参数名 required:是否包含该参数,默认为true,表示该请求路径中必须包含该参数,如果不包含就报错。 defaultValue:默认参数值,如果设置了该值,required=true将失效,自动为false,如果没有传该原创 2021-06-29 11:15:18 · 368 阅读 · 0 评论 -
idea快速从mapper.java跳转到mapper.xml文件的插件
在idea下载一个Free MyBatis plugin的插件原创 2021-06-29 10:33:22 · 1291 阅读 · 0 评论 -
springboot项目配置本地数据库造成时差错误
java.sql.SQLException: 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 specifc time zone value .原创 2020-12-01 14:14:17 · 110 阅读 · 0 评论 -
Spring基础:核心组件介绍,基础环境构建
Spring框架1.简介 Spring是一个开源框架,框架的主要优势之一就是分层架构,分层架构允许使用者选择使用哪一个组件,同时为J2EE应用程序开发提供集成的框架。Spring的用途不局限于服务端的开发。从简单性、可测试性和松耦合的角度而言,任何Java应用都可以从Spring中受益。Spring是一个分层的轻量级开源框架。2.优点分析分层架构一站式,每一个层都提供的解决方案 web层:struts,spring-MVC service层:spring dao层:hiberna.原创 2020-08-27 15:50:41 · 182 阅读 · 0 评论 -
Not match for Select id=int
ResultMap type is com.neusoft.demosb.entity.Lab, Not match for Select id="int"问题截图:问题描述:这个主要是在.xml文件没有对应好类型,将resultMap改为resultType,然后再把LabMap改成java.lang.Integer即可。如图:...原创 2020-06-13 11:23:03 · 4383 阅读 · 1 评论 -
异常:This application has no explicit mapping for /error, so you are seeing this as a fallback.
在把ssm转成springboot项目时,突然报出了这个问题。通过多个贴纸分析,均说是这三个方面的问题:最后看到原因3,实际访问路径与"xxx"不符合,突然想起。这两个路径要加上并对应好,问题解决。...原创 2020-06-14 23:53:32 · 918 阅读 · 0 评论 -
SpringBoot项目启动时报错:org.apache.catalina.LifecycleException: Protocol handler start failed
百度翻译:org.apache.catalina.lifecycleException,协议处理程序启动失败。错误原因:该项目的端口还在,所以启动失败。百度的解决方法:关掉java进程,再重启。但是在我这里,我关闭好几次都没有解决这个问题,所以我把端口换了。问题解决。然后我打包上传到服务器发现,还是有这个问题。解题思路:查看8888端口是否被占用netstat -tunlp |grep 8888确实被占用因此我把端口换成8081再重新打包上传。原创 2020-07-25 00:21:18 · 2607 阅读 · 0 评论 -
@Conditional的使用
作用 根据条件,决定类是否加载到Spring Ioc容器中,在SpringBoot中有大量的运用应用场景 在一些需要条件满足才是实例化的类中,使用此注解,我曾经在项目中需要根据不同的场景使用不同的mq中间件的时候使用过,在mq的实例化bean上,加上此注解,根据配置文件的不同,来决定这个bean是否加载至ioc容器中。使用方法1.实现Conditional接口,实现matches方法public class MqExistsCondition implements Co...原创 2020-08-20 15:45:02 · 422 阅读 · 0 评论 -
spring注解开发的组件注册
在spring的底层中,重要特性是IoC和DI,即是控制反转和依赖注入。spring认为所有组件都应该放在IoC容器中,然后组件之中的关系通过容器自动装配,也就是我们所说的依赖注入。这篇文章主要介绍容器的组件注册管理。以前通常是用配置文件来注册组件。例如在bean配置文件使用bean标签。beans.xml <bean id="person" class="c...原创 2020-02-18 23:32:51 · 109 阅读 · 1 评论 -
@RequestMapping的使用
@RequestMapping:可以用来注释一个控制器类,在这种情况下,所有方法都将映射为相对于类级别的请求,表示该控制器处理的所有请求都被映射到value属性所指示的路径下。通俗的讲@RequestMapping就是用来配置url映射:@RequestMapping("/hello")放在类前面用于给整个类设置映射。 @RequestMapping(value = {"/hell...原创 2020-03-02 20:39:31 · 372 阅读 · 0 评论 -
request 、 session 和 globalsession 三种作用域仅在基于 Web 的应用中使用
Bean的singleton、prototype、request 、 session 和 globalsession五种作用域中,request 、 session 和 globalsession三种作用域仅在基于 Web 的应用中使用。一般在 <bean> 标签中通过 scope 指定作用域类型,也可以在 <beans> 下指定默认全局的 scope 类型。其中 ...原创 2020-03-19 13:48:04 · 3869 阅读 · 0 评论 -
IoC和AOP的实现原理
Ioc的概念IoC(Inversion of Control)指控制反转,是Spring中的一种设计思想以及重要特性。IoC意味着将设计好的类交给容器控制,而不是在对象内部控制。控制,指的是容器控制对象,在传统的开发中,我们通过在对象内部new进行对象创建,而IoC中专门有一个创建对象。反转指的是获取对象的方式发生了反转,以往对外部资源或对象的获取依赖于程序主动通过new引导,现在...原创 2020-03-16 20:58:44 · 2203 阅读 · 0 评论