SpringBoot下我们需要引入Thymeleaf作为模板引擎输出HTML(例如渲染出邮件的HTML或者输出PDF用的HTML等等),但是并不需要它作为view来输出(viewResolver)(例如项目中已经使用了JSP来做view输出了)。 关于SpringBoot整合JSP详见:https://blog.terrynow.com/2021/07/07/springboot-mvc-jsp-and-jstl-implment/ 首先,我们在SpringBoot的pom.xml引入了: <dependen…

2021-12-27 0条评论 1193点热度 0人点赞 admin 阅读全文

SpringBoot项目中,如果要调取项目下的静态文件资源,要怎么做? 如果静态资源放在src/main/resources下,如图: 调用方式,以Service为例,SystemServiceImpl.java如下 @Service("systemService") @Transactional(readOnly = false) @Repository public class SystemServiceImpl implements ISystemService { @Resource(name = "sys…

2021-12-18 0条评论 1225点热度 0人点赞 admin 阅读全文

SpringBoot打包好的jar,如果在Linux服务器上因为一些环境发生了变化,需要修改配置文件(而有些配置文件,我们可能是打包进入了jar的),要怎么样可以方便的修改里面的配置文件呢? 我们知道windows下,因为是图形界面,直接用7zip rar等压缩软件打开jar包,就可以直接修改里面的配置文件并保存了;其实Linux下也是比较方便的: 先执行vim命令(就和你平常直接修改配置文件一样)例如: vim /path/to/spirng_boot-0.0.1-SNAPSHOT.jar 进入编辑模式后,可以看…

2021-12-03 0条评论 1725点热度 0人点赞 admin 阅读全文

今天启动一个交接的项目,发现启动报错,如下错误提示: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. at sun.reflect.Nati…

2021-12-01 5条评论 1600点热度 0人点赞 admin 阅读全文

SpringBoot生成的jar部署到服务器(例如Linux)上后,运行的时候,需要指定具体的配置文件路径 java -Xms128M -Xmx512M -Dconf.home="/opt/vdc/" -Dlog4j.configuration="file:/opt/vdc/log4j.properties" -jar /opt/vdc/vdc-0.0.1-SNAPSHOT.jar --spring.config.location=/opt/vdc/ 如上,是内存参数,是我用了log4j,指定log4j的配置文件路…

2021-11-30 0条评论 715点热度 0人点赞 admin 阅读全文

SpringBoot开发的时候,可能有多个环境,例如开发环境、部署到正式机后,有正式环境,我们可以新建多个spring配置文件,例如: application.yml 代表公共的配置 application-dev.yml 代表开发环境下特有的配置 application-prod.yml 代表生产环境下特有的配置 其中application后面跟着横线+配置名称,dev代表开发环境,prod代表正式环境,后面指定profiles的时候,也只需要跟着横线后面的名称 那启动应用的时候,要怎么让springboot知道…

2021-11-27 0条评论 986点热度 0人点赞 admin 阅读全文

一个SpringBoot的Web项目,打包成jar后上传到CentOS上启动,通命令netstat -ant能看到本地有开启了监听端口(例如8080),但是其他客户端却无法访问,本机却可以:curl http://127.0.0.1:8080 能看到返回的数据 排查后发现,在SpringBoot的配置文件application.properties中,增加: server.port = 8080 server.address = 0.0.0.0 如果是application.yml,则是: server: port…

2021-11-26 0条评论 1160点热度 0人点赞 admin 阅读全文

SpringBoot的拦截器HandlerInterceptor下,我们在public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o)下进行了拦截,对不符合条件的请求,我们一般是返回一个非200的状态代码,例如: @Component public class PersonalInterceptor implements HandlerInterceptor { @Override publi…

2021-10-28 0条评论 1835点热度 0人点赞 admin 阅读全文

SpringBoot下使用如下,spring-boot-starter-data-redis,使用RedisTemplate/StringRedisTemplate封装了Redis的操作,非常的方便了。 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency…

2021-08-30 0条评论 1628点热度 0人点赞 admin 阅读全文

我们用SpringBoot写好的Rest API,在开发阶段,前后端联调的时候,发现前端写的例如vue程序(axios)无法连接API,通过浏览器日志发现报错:No 'Access-Control-Allow-Origin' header is present on the requested resource. 原因是跨域了,为了安全期间,前端的程序和API不是同一个URL,导致无法访问。 网上写的一些SpringBoot解决跨域的,是给Controller增加@CrossOrigin注解,或者配置WebMvcC…

2021-08-18 0条评论 907点热度 0人点赞 admin 阅读全文
145678