Commit dc91b8439c4d71d69fb2244c2283cebc32c1acdc
1 parent
53d41089
教程里关于feign调用拿不到token的问题 #2244
集成xxl-job-2.2.0之后,注解没有删掉,导致启动报端口冲突 #2228
Showing
4 changed files
with
81 additions
and
77 deletions
jeecg-boot/jeecg-boot-module-system/src/main/resources/jeecg/code-template-online/default/one/java/${bussiPackage}/${entityPackage}/vue/${entityName}List.vuei
@@ -95,6 +95,9 @@ | @@ -95,6 +95,9 @@ | ||
95 | <#if po.classType=='pca'> | 95 | <#if po.classType=='pca'> |
96 | <#assign list_need_pca=true> | 96 | <#assign list_need_pca=true> |
97 | </#if> | 97 | </#if> |
98 | +<#if po.classType=='switch'> | ||
99 | +<#assign list_need_switch=true> | ||
100 | +</#if> | ||
98 | </#list> | 101 | </#list> |
99 | <#-- 结束循环 --> | 102 | <#-- 结束循环 --> |
100 | <#t> | 103 | <#t> |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/src/main/java/org/jeecg/config/FeignConfig.java
0 → 100644
1 | +package org.jeecg.config; | ||
2 | + | ||
3 | +import feign.Feign; | ||
4 | +import feign.Logger; | ||
5 | +import feign.RequestInterceptor; | ||
6 | +import feign.codec.Encoder; | ||
7 | +import feign.form.spring.SpringFormEncoder; | ||
8 | +import lombok.extern.slf4j.Slf4j; | ||
9 | +import org.jeecg.common.constant.CommonConstant; | ||
10 | +import org.springframework.beans.factory.ObjectFactory; | ||
11 | +import org.springframework.boot.autoconfigure.AutoConfigureBefore; | ||
12 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
13 | +import org.springframework.boot.autoconfigure.http.HttpMessageConverters; | ||
14 | +import org.springframework.cloud.openfeign.FeignAutoConfiguration; | ||
15 | +import org.springframework.cloud.openfeign.support.SpringEncoder; | ||
16 | +import org.springframework.context.annotation.Bean; | ||
17 | +import org.springframework.context.annotation.Configuration; | ||
18 | +import org.springframework.context.annotation.Primary; | ||
19 | +import org.springframework.context.annotation.Scope; | ||
20 | +import org.springframework.web.context.request.RequestContextHolder; | ||
21 | +import org.springframework.web.context.request.ServletRequestAttributes; | ||
22 | + | ||
23 | +import javax.servlet.http.HttpServletRequest; | ||
24 | + | ||
25 | + | ||
26 | +@ConditionalOnClass(Feign.class) | ||
27 | +@AutoConfigureBefore(FeignAutoConfiguration.class) | ||
28 | +@Slf4j | ||
29 | +@Configuration | ||
30 | +public class FeignConfig { | ||
31 | + | ||
32 | + @Bean | ||
33 | + public RequestInterceptor requestInterceptor() { | ||
34 | + return requestTemplate -> { | ||
35 | + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); | ||
36 | + if (null != attributes) { | ||
37 | + HttpServletRequest request = attributes.getRequest(); | ||
38 | + log.info("Feign request: {}", request.getRequestURI()); | ||
39 | + // 将token信息放入header中 | ||
40 | + String token = request.getHeader(CommonConstant.X_ACCESS_TOKEN); | ||
41 | + if(token==null){ | ||
42 | + token = request.getParameter("token"); | ||
43 | + } | ||
44 | + log.info("Feign request token: {}", token); | ||
45 | + requestTemplate.header(CommonConstant.X_ACCESS_TOKEN, token); | ||
46 | + } | ||
47 | + }; | ||
48 | + } | ||
49 | + | ||
50 | + | ||
51 | + | ||
52 | + /** | ||
53 | + * Feign 客户端的日志记录,默认级别为NONE | ||
54 | + * Logger.Level 的具体级别如下: | ||
55 | + * NONE:不记录任何信息 | ||
56 | + * BASIC:仅记录请求方法、URL以及响应状态码和执行时间 | ||
57 | + * HEADERS:除了记录 BASIC级别的信息外,还会记录请求和响应的头信息 | ||
58 | + * FULL:记录所有请求与响应的明细,包括头信息、请求体、元数据 | ||
59 | + */ | ||
60 | + @Bean | ||
61 | + Logger.Level feignLoggerLevel() { | ||
62 | + return Logger.Level.FULL; | ||
63 | + } | ||
64 | + | ||
65 | + /** | ||
66 | + * Feign支持文件上传 | ||
67 | + * @param messageConverters | ||
68 | + * @return | ||
69 | + */ | ||
70 | + @Bean | ||
71 | + @Primary | ||
72 | + @Scope("prototype") | ||
73 | + public Encoder multipartFormEncoder(ObjectFactory<HttpMessageConverters> messageConverters) { | ||
74 | + return new SpringFormEncoder(new SpringEncoder(messageConverters)); | ||
75 | + } | ||
76 | +} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/src/main/java/org/jeecg/starter/cloud/config/FeignClientConfig.java deleted
1 | -//package org.jeecg.starter.cloud.config; | ||
2 | -// | ||
3 | -//import feign.Feign; | ||
4 | -//import feign.Logger; | ||
5 | -//import feign.RequestInterceptor; | ||
6 | -//import feign.codec.Encoder; | ||
7 | -//import feign.form.spring.SpringFormEncoder; | ||
8 | -//import lombok.extern.slf4j.Slf4j; | ||
9 | -//import org.jeecg.common.constant.CommonConstant; | ||
10 | -//import org.springframework.beans.factory.ObjectFactory; | ||
11 | -//import org.springframework.boot.autoconfigure.AutoConfigureBefore; | ||
12 | -//import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
13 | -//import org.springframework.boot.autoconfigure.http.HttpMessageConverters; | ||
14 | -//import org.springframework.cloud.openfeign.FeignAutoConfiguration; | ||
15 | -//import org.springframework.cloud.openfeign.support.SpringEncoder; | ||
16 | -//import org.springframework.context.annotation.Bean; | ||
17 | -//import org.springframework.context.annotation.Configuration; | ||
18 | -//import org.springframework.context.annotation.Primary; | ||
19 | -//import org.springframework.context.annotation.Scope; | ||
20 | -//import org.springframework.web.context.request.RequestContextHolder; | ||
21 | -//import org.springframework.web.context.request.ServletRequestAttributes; | ||
22 | -// | ||
23 | -//import javax.servlet.http.HttpServletRequest; | ||
24 | -// | ||
25 | -// | ||
26 | -//@ConditionalOnClass(Feign.class) | ||
27 | -//@AutoConfigureBefore(FeignAutoConfiguration.class) | ||
28 | -//@Slf4j | ||
29 | -//@Configuration | ||
30 | -//public class FeignClientConfig { | ||
31 | -// | ||
32 | -// @Bean | ||
33 | -// public RequestInterceptor requestInterceptor() { | ||
34 | -// return requestTemplate -> { | ||
35 | -// ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); | ||
36 | -// if (null != attributes) { | ||
37 | -// HttpServletRequest request = attributes.getRequest(); | ||
38 | -// log.info("Feign request: {}", request.getRequestURI()); | ||
39 | -// // 将token信息放入header中 | ||
40 | -// String token = request.getHeader(CommonConstant.X_ACCESS_TOKEN); | ||
41 | -// if(token==null){ | ||
42 | -// token = request.getParameter("token"); | ||
43 | -// } | ||
44 | -// log.info("Feign request token: {}", token); | ||
45 | -// requestTemplate.header(CommonConstant.X_ACCESS_TOKEN, token); | ||
46 | -// } | ||
47 | -// }; | ||
48 | -// } | ||
49 | -// | ||
50 | -// | ||
51 | -// | ||
52 | -// /** | ||
53 | -// * Feign 客户端的日志记录,默认级别为NONE | ||
54 | -// * Logger.Level 的具体级别如下: | ||
55 | -// * NONE:不记录任何信息 | ||
56 | -// * BASIC:仅记录请求方法、URL以及响应状态码和执行时间 | ||
57 | -// * HEADERS:除了记录 BASIC级别的信息外,还会记录请求和响应的头信息 | ||
58 | -// * FULL:记录所有请求与响应的明细,包括头信息、请求体、元数据 | ||
59 | -// */ | ||
60 | -// @Bean | ||
61 | -// Logger.Level feignLoggerLevel() { | ||
62 | -// return Logger.Level.FULL; | ||
63 | -// } | ||
64 | -// | ||
65 | -// /** | ||
66 | -// * Feign支持文件上传 | ||
67 | -// * @param messageConverters | ||
68 | -// * @return | ||
69 | -// */ | ||
70 | -// @Bean | ||
71 | -// @Primary | ||
72 | -// @Scope("prototype") | ||
73 | -// public Encoder multipartFormEncoder(ObjectFactory<HttpMessageConverters> messageConverters) { | ||
74 | -// return new SpringFormEncoder(new SpringEncoder(messageConverters)); | ||
75 | -// } | ||
76 | -//} |
jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-job/src/main/java/org/jeecg/boot/starter/job/config/XxlJobConfiguration.java
@@ -25,7 +25,8 @@ public class XxlJobConfiguration { | @@ -25,7 +25,8 @@ public class XxlJobConfiguration { | ||
25 | @Autowired | 25 | @Autowired |
26 | private XxlJobProperties xxlJobProperties; | 26 | private XxlJobProperties xxlJobProperties; |
27 | 27 | ||
28 | - @Bean(initMethod = "start", destroyMethod = "destroy") | 28 | + //@Bean(initMethod = "start", destroyMethod = "destroy") |
29 | + @Bean | ||
29 | @ConditionalOnClass() | 30 | @ConditionalOnClass() |
30 | public XxlJobSpringExecutor xxlJobExecutor() { | 31 | public XxlJobSpringExecutor xxlJobExecutor() { |
31 | log.info(">>>>>>>>>>> xxl-job config init."); | 32 | log.info(">>>>>>>>>>> xxl-job config init."); |