最近在采用SpringBoot集成Jersey来构建Restful服务时,遇到无法访问静态资源的问题。经过排查发现是Jersey的ApplicationPath默认为”/”,这样一来就会拦截所有的请求而导致无法访问静态资源。
解决如下:
配置属性文件:application.yml;
内容如下:
server:
port: 8080
spring:
datasource:
name: easyui
url: jdbc:mysql://10.10.128.117:3306/easyui?useUnicode=true&characterEncoding=utf8
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver
mybatis:
mapper-locations: classpath:mapping/*Mapper.xml
type-aliases-package: com.ieds.springbootmybatis.pojo
jersey:
spring.jersey.application-path: rest
配置完成后:
浏览器输入:
http://localhost:8080/rest/userMgr/getAllUsers; 访问形式:http:host:port/rest
本文解决了一个在SpringBoot中集成Jersey构建Restful服务时遇到的问题,即无法访问静态资源。通过调整Jersey的ApplicationPath配置,使其不拦截所有请求,从而实现了静态资源的正常访问。

被折叠的 条评论
为什么被折叠?



