Skip to content

Commit 00865df

Browse files
🏇 拦截器启用禁用配置,更改core包目录,下载上传拦截器,logback.xml优化显示行号, 1.2.2预发布
Former-commit-id: 07727fb081d9e243345f12d1ca6ad43a55d66d36
1 parent f6ff4f0 commit 00865df

23 files changed

+275
-82
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/target/
2+
/classes
23
!.mvn/wrapper/maven-wrapper.jar
34

45
### STS ###

pom.xml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
<groupId>io.geekidea</groupId>
2323
<artifactId>spring-boot-plus</artifactId>
24-
<version>1.2.1.RELEASE</version>
24+
<version>1.2.2.RELEASE</version>
2525
<packaging>jar</packaging>
2626

2727
<name>spring-boot-plus</name>
@@ -56,7 +56,6 @@
5656
<druid.version>1.1.18</druid.version>
5757
<commons-io.version>2.6</commons-io.version>
5858
<reflections.version>0.9.11</reflections.version>
59-
<hibernate-validator.version>6.0.17.Final</hibernate-validator.version>
6059
<commons-codec.version>1.12</commons-codec.version>
6160
<commons-net.version>3.6</commons-net.version>
6261
<jansi.version>1.18</jansi.version>
@@ -108,6 +107,11 @@
108107
<groupId>org.springframework.boot</groupId>
109108
<artifactId>spring-boot-starter-json</artifactId>
110109
</dependency>
110+
<dependency>
111+
<groupId>org.springframework.boot</groupId>
112+
<artifactId>spring-boot-starter-validation</artifactId>
113+
</dependency>
114+
111115
<dependency>
112116
<groupId>org.springframework.boot</groupId>
113117
<artifactId>spring-boot-configuration-processor</artifactId>
@@ -212,12 +216,6 @@
212216
<version>${reflections.version}</version>
213217
</dependency>
214218

215-
<dependency>
216-
<groupId>org.hibernate.validator</groupId>
217-
<artifactId>hibernate-validator</artifactId>
218-
<version>${hibernate-validator.version}</version>
219-
</dependency>
220-
221219
<dependency>
222220
<groupId>org.fusesource.jansi</groupId>
223221
<artifactId>jansi</artifactId>

src/main/java/io/geekidea/springbootplus/SpringBootPlusApplication.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public static void main(String[] args) {
4747
ConfigurableApplicationContext context = SpringApplication.run(SpringBootPlusApplication.class, args);
4848
// 打印项目信息
4949
PrintApplicationInfo.print(context);
50+
/**
51+
* TODO 日志现实行号
52+
* 拦截器配置是否启用,参照文件上传拦截器
53+
*/
5054
}
5155

5256
}

src/main/java/io/geekidea/springbootplus/common/web/filter/RequestPathFilter.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ public class RequestPathFilter implements Filter {
3535
private static List<String> excludes = new ArrayList<>();
3636

3737
static {
38-
excludes.add("/api");
39-
excludes.add("/health/");
38+
// 控制台日志忽略spring boot admin访问路径
39+
excludes.add("/actuator");
40+
excludes.add("/instances");
4041
excludes.add("/logfile");
42+
excludes.add("/sba-settings.js");
43+
excludes.add("/assets/img/favicon.png");
4144
}
4245

4346
@Override
@@ -50,6 +53,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
5053
HttpServletRequest req = (HttpServletRequest) request;
5154
String path = req.getServletPath();
5255
String url = req.getRequestURL().toString();
56+
5357
boolean isOut = true;
5458
for (String p : excludes){
5559
if (path.startsWith(p)){

src/main/java/io/geekidea/springbootplus/common/web/interceptor/PermissionInterceptor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class PermissionInterceptor extends HandlerInterceptorAdapter {
3535
@Override
3636
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
3737
throws Exception {
38+
log.info(request.getRequestURI());
3839
log.info("\n\nPermissionInterceptor...\n\n");
3940
return true;
4041
}

src/main/java/io/geekidea/springbootplus/config/core/SpringBootPlusConfig.java renamed to src/main/java/io/geekidea/springbootplus/core/SpringBootPlusConfig.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.geekidea.springbootplus.config.core;
16+
package io.geekidea.springbootplus.core;
1717

1818
import io.geekidea.springbootplus.common.aop.LogAop;
19-
import io.geekidea.springbootplus.common.web.interceptor.DownloadInterceptor;
20-
import io.geekidea.springbootplus.common.web.interceptor.PermissionInterceptor;
21-
import io.geekidea.springbootplus.common.web.interceptor.ResourceInterceptor;
22-
import io.geekidea.springbootplus.common.web.interceptor.TokenTimeoutInterceptor;
19+
import io.geekidea.springbootplus.common.web.interceptor.*;
20+
import io.geekidea.springbootplus.resource.web.interceptor.DownloadInterceptor;
21+
import io.geekidea.springbootplus.resource.web.interceptor.ResourceInterceptor;
22+
import io.geekidea.springbootplus.resource.web.interceptor.UploadInterceptor;
2323
import io.geekidea.springbootplus.security.interceptor.JwtInterceptor;
2424
import lombok.extern.slf4j.Slf4j;
2525
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -81,6 +81,16 @@ public TokenTimeoutInterceptor tokenTimeoutInterceptor(){
8181
return tokenTimeoutInterceptor;
8282
}
8383

84+
/**
85+
* 上传拦截器
86+
* @return
87+
*/
88+
@Bean
89+
public UploadInterceptor uploadInterceptor(){
90+
UploadInterceptor uploadInterceptor = new UploadInterceptor();
91+
return uploadInterceptor;
92+
}
93+
8494
/**
8595
* 资源拦截器
8696
* @return

src/main/java/io/geekidea/springbootplus/config/core/SpringBootPlusInterceptorConfig.java renamed to src/main/java/io/geekidea/springbootplus/core/SpringBootPlusInterceptorConfig.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.geekidea.springbootplus.config.core;
17+
package io.geekidea.springbootplus.core;
1818

1919
import lombok.Data;
2020
import lombok.experimental.Accessors;
@@ -50,6 +50,11 @@ public class SpringBootPlusInterceptorConfig implements Serializable {
5050
*/
5151
private InterceptorConfig resourceConfig;
5252

53+
/**
54+
* 上传拦截器
55+
*/
56+
private InterceptorConfig uploadConfig;
57+
5358
/**
5459
* 下载拦截器
5560
*/
@@ -58,6 +63,11 @@ public class SpringBootPlusInterceptorConfig implements Serializable {
5863
@Data
5964
public static class InterceptorConfig {
6065

66+
/**
67+
* 是否启用
68+
*/
69+
private boolean enabled;
70+
6171
/**
6272
* 排除路径
6373
*/

src/main/java/io/geekidea/springbootplus/config/core/SpringBootPlusProperties.java renamed to src/main/java/io/geekidea/springbootplus/core/SpringBootPlusProperties.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.geekidea.springbootplus.config.core;
17+
package io.geekidea.springbootplus.core;
1818

1919
import lombok.Data;
2020
import lombok.experimental.Accessors;
@@ -60,7 +60,6 @@ public class SpringBootPlusProperties {
6060
@NestedConfigurationProperty
6161
private SpringBootPlusInterceptorConfig interceptorConfig;
6262

63-
6463
/**
6564
* 上传目录
6665
*/

src/main/java/io/geekidea/springbootplus/config/WebMvcConfig.java renamed to src/main/java/io/geekidea/springbootplus/core/SpringBootPlusWebMvcConfig.java

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.geekidea.springbootplus.config;
17+
package io.geekidea.springbootplus.core;
1818

19-
import io.geekidea.springbootplus.common.web.interceptor.DownloadInterceptor;
19+
import com.alibaba.fastjson.JSON;
2020
import io.geekidea.springbootplus.common.web.interceptor.PermissionInterceptor;
21-
import io.geekidea.springbootplus.common.web.interceptor.ResourceInterceptor;
2221
import io.geekidea.springbootplus.common.web.interceptor.TokenTimeoutInterceptor;
23-
import io.geekidea.springbootplus.config.core.SpringBootPlusProperties;
22+
import io.geekidea.springbootplus.resource.web.interceptor.DownloadInterceptor;
23+
import io.geekidea.springbootplus.resource.web.interceptor.ResourceInterceptor;
24+
import io.geekidea.springbootplus.resource.web.interceptor.UploadInterceptor;
2425
import io.geekidea.springbootplus.security.interceptor.JwtInterceptor;
2526
import lombok.extern.slf4j.Slf4j;
2627
import org.springframework.beans.factory.annotation.Autowired;
@@ -29,13 +30,16 @@
2930
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
3031
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
3132

33+
import javax.annotation.PostConstruct;
34+
3235
/**
36+
* WebMvc配置
3337
* @author geekidea
3438
* @date 2018-11-08
3539
*/
3640
@Configuration
3741
@Slf4j
38-
public class WebMvcConfig implements WebMvcConfigurer {
42+
public class SpringBootPlusWebMvcConfig implements WebMvcConfigurer {
3943

4044
@Autowired
4145
private SpringBootPlusProperties springBootPlusProperties;
@@ -52,34 +56,54 @@ public class WebMvcConfig implements WebMvcConfigurer {
5256
@Autowired
5357
private ResourceInterceptor resourceInterceptor;
5458

59+
@Autowired
60+
private UploadInterceptor uploadInterceptor;
61+
5562
@Autowired
5663
private DownloadInterceptor downloadInterceptor;
5764

65+
@PostConstruct
66+
public void init(){
67+
// 打印SpringBootPlusProperties配置信息
68+
log.info("SpringBootPlusProperties:{}", JSON.toJSONString(springBootPlusProperties));
69+
}
70+
5871
@Override
5972
public void addInterceptors(InterceptorRegistry registry) {
73+
SpringBootPlusInterceptorConfig interceptorConfig = springBootPlusProperties.getInterceptorConfig();
74+
75+
// 上传拦截器
76+
registry.addInterceptor(uploadInterceptor)
77+
.addPathPatterns(interceptorConfig.getUploadConfig().getIncludePath());
78+
6079
// 资源拦截器注册
6180
registry.addInterceptor(resourceInterceptor)
62-
.addPathPatterns(springBootPlusProperties.getInterceptorConfig().getResourceConfig().getIncludePath());
81+
.addPathPatterns(interceptorConfig.getResourceConfig().getIncludePath());
6382

6483
// 下载拦截器注册
6584
registry.addInterceptor(downloadInterceptor)
66-
.addPathPatterns(springBootPlusProperties.getInterceptorConfig().getDownloadConfig().getIncludePath());
67-
68-
// // JWT拦截器注册
69-
// registry.addInterceptor(jwtInterceptor)
70-
// .addPathPatterns("/**")
71-
// .excludePathPatterns(springBootPlusProperties.getInterceptorConfig().getJwtConfig().getExcludePath());
72-
//
73-
// // TOKEN超时拦截器注册
74-
// registry.addInterceptor(tokenTimeoutInterceptor)
75-
// .addPathPatterns("/**")
76-
// .excludePathPatterns(springBootPlusProperties.getInterceptorConfig().getTokenTimeoutConfig().getExcludePath());
77-
//
78-
// // 权限拦截器注册
79-
// registry.addInterceptor(permissionInterceptor)
80-
// .addPathPatterns("/**")
81-
// .excludePathPatterns(springBootPlusProperties.getInterceptorConfig().getPermissionConfig().getExcludePath());
85+
.addPathPatterns(interceptorConfig.getDownloadConfig().getIncludePath());
86+
87+
if (interceptorConfig.getJwtConfig().isEnabled()){
88+
// JWT拦截器注册
89+
registry.addInterceptor(jwtInterceptor)
90+
.addPathPatterns(interceptorConfig.getJwtConfig().getIncludePath())
91+
.excludePathPatterns(interceptorConfig.getJwtConfig().getExcludePath());
92+
}
8293

94+
if (interceptorConfig.getTokenTimeoutConfig().isEnabled()){
95+
// TOKEN超时拦截器注册
96+
registry.addInterceptor(tokenTimeoutInterceptor)
97+
.addPathPatterns(interceptorConfig.getTokenTimeoutConfig().getIncludePath())
98+
.excludePathPatterns(interceptorConfig.getTokenTimeoutConfig().getExcludePath());
99+
}
100+
101+
if (interceptorConfig.getPermissionConfig().isEnabled()){
102+
// 权限拦截器注册
103+
registry.addInterceptor(permissionInterceptor)
104+
.addPathPatterns(interceptorConfig.getPermissionConfig().getIncludePath())
105+
.excludePathPatterns(interceptorConfig.getPermissionConfig().getExcludePath());
106+
}
83107
}
84108

85109
@Override
@@ -98,4 +122,5 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
98122
registry.addResourceHandler(springBootPlusProperties.getResourceAccessPatterns())
99123
.addResourceLocations("file:" + springBootPlusProperties.getUploadPath());
100124
}
125+
101126
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package io.geekidea.springbootplus.resource;

0 commit comments

Comments
 (0)