Skip to content

Commit

Permalink
fix: 注册自定义的 web Filter 条件错误,导致 Filter 没有被注册
Browse files Browse the repository at this point in the history
  • Loading branch information
myoss committed Dec 28, 2018
1 parent 9bec4cd commit 7da085a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,24 @@ public class WebConstants {
/**
* 缓存配置前缀
*/
public static final String CONFIG_PREFIX = MyossConstants.CONFIG_PREFIX + ".web";
public static final String CONFIG_PREFIX = MyossConstants.CONFIG_PREFIX
+ ".web";
/**
* OkHttp3连接池属性配置前缀
*/
public static final String OK_HTTP3_CONNECTION_CONFIG_PREFIX = MyossConstants.CONFIG_PREFIX
public static final String OK_HTTP3_CONNECTION_CONFIG_PREFIX = MyossConstants.CONFIG_PREFIX
+ ".ok-http3.connection-pool";

/**
* restTemplate4OkHttp3 spring bean name
*/
public static final String REST_TEMPLATE4_OK_HTTP3_BEAN_NAME = "restTemplate4OkHttp3";
public static final String REST_TEMPLATE4_OK_HTTP3_BEAN_NAME = "restTemplate4OkHttp3";
/**
* readerBodyHttpServletRequestFilter spring bean name
*/
public static final String READER_BODY_HTTP_SERVLET_REQUEST_FILTER_BEAN_NAME = "readerBodyHttpServletRequestFilter";
/**
* webRequestLogFilter spring bean name
*/
public static final String WEB_REQUEST_LOG_FILTER_BEAN_NAME = "webRequestLogFilter";
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.HttpMessageConverter;
Expand All @@ -32,6 +32,7 @@
import com.alibaba.fastjson.support.config.FastJsonConfig;

import app.myoss.cloud.core.spring.boot.config.FastJsonAutoConfiguration;
import app.myoss.cloud.web.constants.WebConstants;
import app.myoss.cloud.web.spring.web.servlet.filter.LogWebRequestFilter;
import app.myoss.cloud.web.spring.web.servlet.filter.ReaderBodyHttpServletRequestFilter;

Expand Down Expand Up @@ -64,8 +65,8 @@ public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
* @return 可以多次读取 {@link HttpServletRequest#getReader()} 和
* {@link HttpServletRequest#getInputStream()} 中的内容
*/
@ConditionalOnBean
@Bean
@ConditionalOnMissingBean(name = WebConstants.READER_BODY_HTTP_SERVLET_REQUEST_FILTER_BEAN_NAME)
@Bean(name = WebConstants.READER_BODY_HTTP_SERVLET_REQUEST_FILTER_BEAN_NAME)
public FilterRegistrationBean<ReaderBodyHttpServletRequestFilter> readerBodyHttpServletRequestFilter() {
FilterRegistrationBean<ReaderBodyHttpServletRequestFilter> registration = new FilterRegistrationBean<>();
registration.setFilter(new ReaderBodyHttpServletRequestFilter());
Expand All @@ -77,8 +78,8 @@ public FilterRegistrationBean<ReaderBodyHttpServletRequestFilter> readerBodyHttp
*
* @return 记录web请求的日志信息过滤器
*/
@ConditionalOnBean
@Bean
@ConditionalOnMissingBean(name = WebConstants.WEB_REQUEST_LOG_FILTER_BEAN_NAME)
@Bean(name = WebConstants.WEB_REQUEST_LOG_FILTER_BEAN_NAME)
public FilterRegistrationBean<LogWebRequestFilter> webRequestLogFilter() {
FilterRegistrationBean<LogWebRequestFilter> registration = new FilterRegistrationBean<>();
registration.setFilter(new LogWebRequestFilter(true, true));
Expand Down

0 comments on commit 7da085a

Please sign in to comment.