
Spring Boot
Tong XU
欣赏简洁的代码是一种赏心悦目的事情。
展开
-
Spring Boot静态资源访问
@Configurationpublic class CorsConfigure extends WebMvcConfigurationSupport { /* * 这里主要为了解决跨域问题,所以重写addCorsMappings方法 */ @Override protected void addCorsMappings(CorsRegistry registry) { ...原创 2020-01-07 21:55:22 · 179 阅读 · 0 评论 -
Spring Boot上传图片到项目根路径文件夹下
如果想让 Spring Boot上传文件,上传到项目的根路径下(不是容器实例,这里很容易出错)Spring Boot上传图片到项目根路径文件夹下UploadUtils.java注意构建“图片文件夹路径”public class UploadUtils { // 项目根路径下的目录 -- SpringBoot static 目录相当于是根路径下(Sp...转载 2020-01-07 15:40:30 · 4870 阅读 · 3 评论 -
Spring Boot+WebSocket实现点对点式
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.o原创 2019-02-24 16:09:23 · 394 阅读 · 0 评论 -
org.thymeleaf.exceptions.TemplateInputException:
在application.properties中加上如下配置:spring.thymeleaf.prefix=classpath:/templates原创 2019-02-24 19:09:08 · 686 阅读 · 0 评论 -
Spring Boot项目下注入SessionFactory
@Autowired private EntityManagerFactory entityManagerFactory; public Session getSession() { return entityManagerFactory.unwrap(SessionFactory.class).openSession(); }通过getSessio...原创 2019-02-19 21:29:56 · 5641 阅读 · 0 评论 -
Spring Boot解决跨域
package com.jxufe.demotest.config;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.web.cors.CorsConfigurat...原创 2019-03-01 14:44:46 · 102 阅读 · 0 评论 -
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' he
今天,在一个Spring Boot项目中遇到了跨域访问的问题。通过查阅相关资料,可知可以在配置类上重写一个方法来实现跨域访问。package com.jxufe.demotest.config;import org.springframework.context.annotation.Configuration;import org.springframework.web.se...原创 2019-02-20 19:36:00 · 13394 阅读 · 0 评论 -
Spring Batch相关的表
你需要在数据库中建立springbatch的相关元数据表,所以你需要在数据库中执行如下来自官方元数据模式的脚本。-- do not edit this file-- BATCH JOB 实例表 包含与aJobInstance相关的所有信息-- JOB ID由batch_job_seq分配-- JOB 名称,与spring配置一致-- JOB KEY 对job参数的MD5编码,正因为有...原创 2019-03-06 13:31:59 · 3096 阅读 · 0 评论 -
linux系统上文件上传,如何填写路径
package com.jxufe.batch.controller;import java.io.File;import java.io.IOException;import org.springframework.batch.core.Job;import org.springframework.batch.core.JobParameters;import org.sprin...原创 2019-03-06 21:28:29 · 5123 阅读 · 2 评论 -
Spring Boot+WebSocket实现广播式
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.o原创 2019-02-24 13:36:21 · 493 阅读 · 0 评论 -
Spring Boot整合Swagger2
引入依赖 需导入Swagger,Swagger-UI的依赖。 <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> ...原创 2019-02-13 11:39:50 · 192 阅读 · 0 评论 -
一个Spring Boot集成Redis的小案例
新建Spring Boot项目搭建Spring Boot项目,依赖为Redis和Web。领域模型类package com.jxufe.redisProj1.domain;import java.io.Serializable;public class Person implements Serializable { private static final long se...原创 2019-01-31 13:05:40 · 188 阅读 · 0 评论 -
Spring Boot中在application.properties中加入server.context-path=/helloboot没用
需要将server.context-path改为server.servlet.context-path = /helloboot原创 2019-01-21 15:09:04 · 1323 阅读 · 2 评论 -
Spring Boot配置hibernate显示sql语句和格式化sql语句
server.port=8989spring.datasource.url=jdbc:mysql://localhost:3306/weather?useUnicode=true&characterEncoding=UTF-8spring.datasource.username=rootspring.datasource.password=123456spring.datasou...原创 2019-02-04 11:51:46 · 4877 阅读 · 0 评论 -
Spring Boot集成JPA的Column注解命名字段无效的问题
偶然发现,Spring Boot集成jpa编写实体类的时候,默认使用的命名策略是下划线分隔的字段命名。Spring Boot版本:1.5.4.release数据表:id int,userName varchar(50)那么如下的映射:@Data@Entity@Table(name="t_users")@NoArgsConstructor@AllArgsConstr...转载 2019-01-29 14:09:31 · 1217 阅读 · 0 评论 -
springboot报错Connection is not available, request timed out after 30001ms.
需要在配置文件中加上: spring.datasource.hikari.read-only=falsespring.datasource.hikari.connection-timeout=60000spring.datasource.hikari.idle-timeout=60000spring.datasource.hikari.validation-timeout=3000s...原创 2019-02-21 15:56:37 · 12030 阅读 · 3 评论 -
Refused to execute script from '....js' because its MIME type ('text/html') is not executable...
问题描述在整合 Spring Boot、Spring Security、Thymeleaf 的练习中,对页面进行调试时,发现如下错误提示: Refused to execute script from ‘http://localhost:8080/codelib-springsecurity-sample-web/js/ie10-viewport-bug-workaround.js’ beca...转载 2019-02-11 15:49:10 · 8360 阅读 · 0 评论 -
Thymeleaf整合Spring Security,解析sec标签没有效果
今天学习了Spring Security,尝试将其和Thymeleaf进行整合。<!DOCTYPE html><html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5"><head>&l...原创 2019-02-11 17:55:29 · 9638 阅读 · 10 评论 -
Spring Boot 整合 Redis 实现缓存操作
本文提纲一、缓存的应用场景二、更新缓存的策略三、运行 springboot-mybatis-redis 工程案例四、springboot-mybatis-redis 工程代码配置详解 运行环境:Mac OS 10.12.xJDK 8 +Redis 3.2.8Spring Boot 1.5.1.RELEASE 一、缓存的应用场景什么是缓存?在互...转载 2019-02-18 14:43:16 · 177 阅读 · 0 评论 -
Spring Boot的声明式事务
在实际使用中,使用Spring Boot默认的配置就能满足我们绝大多数需求。在本节的实战里,我们将演示如何使用@Transactional使用异常导致数据回滚和使用异常让数据不会滚。 1.新建Spring Boot项目新建Spring Boot项目,依赖为JPA,Web。由于本项目连接了SQL Server数据库,因此多一个依赖SQL Server。pom.xml...原创 2019-01-25 15:22:01 · 131 阅读 · 0 评论