Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
commons
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DevOps
commons
Commits
cda0cd2b
Commit
cda0cd2b
authored
May 09, 2018
by
xiaoguang.xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix : 去除对 spring-webmvc 的依赖
parent
a7edc762
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
68 deletions
+65
-68
pom.xml
brave-spring-boot-starter/pom.xml
+2
-2
BraveAutoConfiguration.java
...roup/tech/brave/configuration/BraveAutoConfiguration.java
+63
-66
No files found.
brave-spring-boot-starter/pom.xml
View file @
cda0cd2b
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<brave.version>
4.19.1
</brave.version>
<brave.version>
4.19.1
</brave.version>
<zipkin-reporter2.version>
2.5.0
</zipkin-reporter2.version>
<zipkin-reporter2.version>
2.5.0
</zipkin-reporter2.version>
<okhttp.version>
3.10.0
</okhttp.version>
</properties>
</properties>
<dependencies>
<dependencies>
...
@@ -28,11 +29,10 @@
...
@@ -28,11 +29,10 @@
<artifactId>
httpclient
</artifactId>
<artifactId>
httpclient
</artifactId>
<optional>
true
</optional>
<optional>
true
</optional>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
com.squareup.okhttp3
</groupId>
<groupId>
com.squareup.okhttp3
</groupId>
<artifactId>
okhttp
</artifactId>
<artifactId>
okhttp
</artifactId>
<version>
3.10.0
</version>
<version>
${okhttp.version}
</version>
<optional>
true
</optional>
<optional>
true
</optional>
</dependency>
</dependency>
...
...
brave-spring-boot-starter/src/main/java/cn/quantgroup/tech/brave/configuration/BraveAutoConfiguration.java
View file @
cda0cd2b
...
@@ -22,21 +22,16 @@ import org.apache.http.client.HttpClient;
...
@@ -22,21 +22,16 @@ import org.apache.http.client.HttpClient;
import
org.apache.http.impl.client.HttpClientBuilder
;
import
org.apache.http.impl.client.HttpClientBuilder
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.AutoConfigureOrder
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Condition
;
import
org.springframework.context.annotation.ConditionContext
;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.core.type.AnnotatedTypeMetadata
;
import
org.springframework.http.client.ClientHttpRequestInterceptor
;
import
org.springframework.http.client.ClientHttpRequestInterceptor
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.servlet.config.annotation.EnableWebMvc
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
import
zipkin2.Span
;
import
zipkin2.Span
;
...
@@ -57,48 +52,35 @@ import java.util.List;
...
@@ -57,48 +52,35 @@ import java.util.List;
*/
*/
@Slf4j
@Slf4j
@Configuration
@Configuration
@AutoConfigureOrder
@Conditional
(
BraveAutoConfiguration
.
BraveSet
.
class
)
public
class
BraveAutoConfiguration
{
public
class
BraveAutoConfiguration
{
static
final
class
BraveSet
implements
Condition
{
@Override
public
boolean
matches
(
ConditionContext
context
,
AnnotatedTypeMetadata
a
)
{
return
!
isEmpty
(
context
.
getEnvironment
().
getProperty
(
"tech.brave.enabled"
));
}
private
static
boolean
isEmpty
(
String
s
)
{
return
s
==
null
||
s
.
isEmpty
();
}
}
@Configuration
@Configuration
@ConditionalOnProperty
(
prefix
=
"tech.brave"
,
name
=
"enabled"
,
havingValue
=
"false"
)
public
static
class
BraveUntEnabled
{
public
static
class
BraveUntEnabled
{
@Configuration
@Configuration
@ConditionalOnClass
(
RabbitTemplate
.
class
)
@ConditionalOnClass
(
RabbitTemplate
.
class
)
@ConditionalOnProperty
(
prefix
=
"tech.brave"
,
name
=
"enabled"
,
havingValue
=
"false"
)
@ConditionalOnProperty
(
prefix
=
"tech.brave"
,
name
=
"enabled"
,
havingValue
=
"false"
,
matchIfMissing
=
true
)
public
static
class
RabbitTemplateEnable
{
public
static
class
RabbitTemplateEnable
{
/**
/**
* 提供RabbitTemplateBuilder,业务系统需要使用该Builder生成RabbitTemplate
* 提供RabbitTemplateBuilder,业务系统需要使用该Builder生成RabbitTemplate
*
*
* @return
* @return
*/
*/
@Bean
(
name
=
"techRabbitTemplateBuilder"
)
@Bean
(
name
=
"techRabbitBuilder"
)
public
ITechRabbitBuilder
rabbitTemplate
Builder
()
{
public
ITechRabbitBuilder
techRabbit
Builder
()
{
return
new
TechRabbitBuilderNoTrace
();
return
new
TechRabbitBuilderNoTrace
();
}
}
}
}
@Configuration
@Configuration
@ConditionalOnClass
(
HttpClient
.
class
)
@ConditionalOnClass
(
HttpClient
.
class
)
@ConditionalOnProperty
(
prefix
=
"tech.brave"
,
name
=
"enabled"
,
havingValue
=
"false"
)
@ConditionalOnProperty
(
prefix
=
"tech.brave"
,
name
=
"enabled"
,
havingValue
=
"false"
,
matchIfMissing
=
true
)
public
static
class
HttpClientEnable
{
public
static
class
HttpClientEnable
{
/**
/**
* 提供HttpClientBuilderBean
* 提供HttpClientBuilderBean
*
*
* @return
* @return
*/
*/
@Bean
(
name
=
"techHttpClientBuilder"
)
@Bean
(
name
=
"techHttpClientBuilder"
)
public
HttpClientBuilder
httpClientBuilder
()
{
public
HttpClientBuilder
httpClientBuilder
()
{
log
.
info
(
"注册HttpClientBuilder"
);
log
.
info
(
"注册HttpClientBuilder"
);
return
HttpClientBuilder
.
create
();
return
HttpClientBuilder
.
create
();
...
@@ -106,8 +88,8 @@ public class BraveAutoConfiguration {
...
@@ -106,8 +88,8 @@ public class BraveAutoConfiguration {
}
}
@Configuration
@Configuration
@ConditionalOnClass
(
OkHttpClient
.
class
)
@ConditionalOnClass
(
OkHttpClient
.
class
)
@ConditionalOnProperty
(
prefix
=
"tech.brave"
,
name
=
"enabled"
,
havingValue
=
"false"
)
@ConditionalOnProperty
(
prefix
=
"tech.brave"
,
name
=
"enabled"
,
havingValue
=
"false"
,
matchIfMissing
=
true
)
public
static
class
OkHttpClientEnable
{
public
static
class
OkHttpClientEnable
{
/**
/**
...
@@ -115,7 +97,7 @@ public class BraveAutoConfiguration {
...
@@ -115,7 +97,7 @@ public class BraveAutoConfiguration {
*
*
* @return
* @return
*/
*/
@Bean
(
name
=
"techOkHttpClientBuilder"
)
@Bean
(
name
=
"techOkHttpClientBuilder"
)
public
OkHttpClient
.
Builder
okHttpClientBuilder
()
{
public
OkHttpClient
.
Builder
okHttpClientBuilder
()
{
log
.
info
(
"注册OkHttpClient.Builder"
);
log
.
info
(
"注册OkHttpClient.Builder"
);
return
new
OkHttpClient
.
Builder
();
return
new
OkHttpClient
.
Builder
();
...
@@ -123,15 +105,15 @@ public class BraveAutoConfiguration {
...
@@ -123,15 +105,15 @@ public class BraveAutoConfiguration {
}
}
@Configuration
@Configuration
@ConditionalOnClass
(
RestTemplate
.
class
)
@ConditionalOnClass
(
RestTemplate
.
class
)
@ConditionalOnProperty
(
prefix
=
"tech.brave"
,
name
=
"enabled"
,
havingValue
=
"false"
)
@ConditionalOnProperty
(
prefix
=
"tech.brave"
,
name
=
"enabled"
,
havingValue
=
"false"
,
matchIfMissing
=
true
)
public
static
class
RestTemplateEnable
{
public
static
class
RestTemplateEnable
{
/**
/**
* 提供RestTemplate
* 提供RestTemplate
*
*
* @return
* @return
*/
*/
@Bean
(
name
=
"techRestTemplate"
)
@Bean
(
name
=
"techRestTemplate"
)
public
RestTemplate
restTemplate
()
{
public
RestTemplate
restTemplate
()
{
log
.
info
(
"添加restTemplate拦截器"
);
log
.
info
(
"添加restTemplate拦截器"
);
return
new
RestTemplate
();
return
new
RestTemplate
();
...
@@ -141,11 +123,9 @@ public class BraveAutoConfiguration {
...
@@ -141,11 +123,9 @@ public class BraveAutoConfiguration {
}
}
@Configuration
@Configuration
@EnableWebMvc
@EnableConfigurationProperties
({
BraveProperties
.
class
,
ServiceProperties
.
class
})
@EnableConfigurationProperties
(
{
BraveProperties
.
class
,
ServiceProperties
.
class
}
)
@ConditionalOnProperty
(
prefix
=
"tech.brave"
,
name
=
"enabled"
,
havingValue
=
"true"
,
matchIfMissing
=
true
)
@ConditionalOnProperty
(
prefix
=
"tech.brave"
,
name
=
"enabled"
,
havingValue
=
"true"
)
public
static
class
BraveEnabled
{
@Import
(
SpanCustomizingAsyncHandlerInterceptor
.
class
)
public
static
class
BraveEnabled
extends
WebMvcConfigurerAdapter
{
@Autowired
@Autowired
private
BraveProperties
braveProperties
;
private
BraveProperties
braveProperties
;
...
@@ -153,9 +133,6 @@ public class BraveAutoConfiguration {
...
@@ -153,9 +133,6 @@ public class BraveAutoConfiguration {
private
ServiceProperties
serviceProperties
;
private
ServiceProperties
serviceProperties
;
@Autowired
private
SpanCustomizingAsyncHandlerInterceptor
spanCustomizingAsyncHandlerInterceptor
;
@Bean
@Bean
@ConditionalOnMissingBean
@ConditionalOnMissingBean
Sender
sender
()
{
Sender
sender
()
{
...
@@ -185,26 +162,46 @@ public class BraveAutoConfiguration {
...
@@ -185,26 +162,46 @@ public class BraveAutoConfiguration {
return
HttpTracing
.
create
(
tracing
);
return
HttpTracing
.
create
(
tracing
);
}
}
@Configuration
@ConditionalOnWebApplication
@ConditionalOnClass
({
Filter
.
class
})
@ConditionalOnProperty
(
prefix
=
"tech.brave"
,
name
=
"enabled"
,
havingValue
=
"true"
,
matchIfMissing
=
true
)
public
static
class
ServletEnable
{
/**
/**
* 创建一个bean
* 创建一个bean
*
*
* @return
* @return
*/
*/
@Bean
(
name
=
"techDelegatingTracingFilter"
)
@Bean
(
name
=
"techDelegatingTracingFilter"
)
public
Filter
delegatingTracingFilter
()
{
public
Filter
delegatingTracingFilter
()
{
log
.
info
(
"注册DelegatingTracingFilter"
);
log
.
info
(
"注册DelegatingTracingFilter"
);
return
new
DelegatingTracingFilter
();
return
new
DelegatingTracingFilter
();
}
}
}
@Configuration
@ConditionalOnClass
({
WebMvcConfigurerAdapter
.
class
})
@Import
(
SpanCustomizingAsyncHandlerInterceptor
.
class
)
@ConditionalOnProperty
(
prefix
=
"tech.brave"
,
name
=
"enabled"
,
havingValue
=
"true"
,
matchIfMissing
=
true
)
public
static
class
WebMvcEnable
extends
WebMvcConfigurerAdapter
{
@Autowired
private
SpanCustomizingAsyncHandlerInterceptor
spanCustomizingAsyncHandlerInterceptor
;
@Override
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
log
.
info
(
"添加braveWebmvc拦截器"
);
log
.
info
(
"添加braveWebmvc拦截器"
);
registry
.
addInterceptor
(
spanCustomizingAsyncHandlerInterceptor
);
registry
.
addInterceptor
(
spanCustomizingAsyncHandlerInterceptor
);
}
}
}
@Configuration
@Configuration
@ConditionalOnClass
(
RabbitTemplate
.
class
)
@ConditionalOnClass
(
RabbitTemplate
.
class
)
@ConditionalOnProperty
(
prefix
=
"tech.brave"
,
name
=
"enabled"
,
havingValue
=
"true"
)
@ConditionalOnProperty
(
prefix
=
"tech.brave"
,
name
=
"enabled"
,
havingValue
=
"true"
,
matchIfMissing
=
true
)
public
static
class
RabbitTemplateEnable
{
public
static
class
RabbitTemplateEnable
{
/**
/**
* 提供RabbitTemplateBuilder,业务系统需要使用该Builder生成RabbitTemplate
* 提供RabbitTemplateBuilder,业务系统需要使用该Builder生成RabbitTemplate
...
@@ -212,15 +209,15 @@ public class BraveAutoConfiguration {
...
@@ -212,15 +209,15 @@ public class BraveAutoConfiguration {
* @param tracing
* @param tracing
* @return
* @return
*/
*/
@Bean
(
name
=
"techRabbitBuilder"
)
@Bean
(
name
=
"techRabbitBuilder"
)
public
ITechRabbitBuilder
rabbitTemplateBuilder
(
Tracing
tracing
)
{
public
ITechRabbitBuilder
rabbitTemplateBuilder
(
Tracing
tracing
)
{
return
new
TechRabbitBuilderTrace
(
tracing
);
return
new
TechRabbitBuilderTrace
(
tracing
);
}
}
}
}
@Configuration
@Configuration
@ConditionalOnClass
(
HttpClient
.
class
)
@ConditionalOnClass
(
HttpClient
.
class
)
@ConditionalOnProperty
(
prefix
=
"tech.brave"
,
name
=
"enabled"
,
havingValue
=
"true"
)
@ConditionalOnProperty
(
prefix
=
"tech.brave"
,
name
=
"enabled"
,
havingValue
=
"true"
,
matchIfMissing
=
true
)
public
static
class
HttpClientEnable
{
public
static
class
HttpClientEnable
{
/**
/**
* 提供HttpClientBuilderBean
* 提供HttpClientBuilderBean
...
@@ -228,7 +225,7 @@ public class BraveAutoConfiguration {
...
@@ -228,7 +225,7 @@ public class BraveAutoConfiguration {
* @param tracing
* @param tracing
* @return
* @return
*/
*/
@Bean
(
name
=
"techHttpClientBuilder"
)
@Bean
(
name
=
"techHttpClientBuilder"
)
public
HttpClientBuilder
httpClientBuilder
(
Tracing
tracing
)
{
public
HttpClientBuilder
httpClientBuilder
(
Tracing
tracing
)
{
log
.
info
(
"注册braveHttpClientBuilder"
);
log
.
info
(
"注册braveHttpClientBuilder"
);
return
TracingHttpClientBuilder
.
create
(
tracing
);
return
TracingHttpClientBuilder
.
create
(
tracing
);
...
@@ -236,8 +233,8 @@ public class BraveAutoConfiguration {
...
@@ -236,8 +233,8 @@ public class BraveAutoConfiguration {
}
}
@Configuration
@Configuration
@ConditionalOnClass
(
OkHttpClient
.
class
)
@ConditionalOnClass
(
OkHttpClient
.
class
)
@ConditionalOnProperty
(
prefix
=
"tech.brave"
,
name
=
"enabled"
,
havingValue
=
"true"
)
@ConditionalOnProperty
(
prefix
=
"tech.brave"
,
name
=
"enabled"
,
havingValue
=
"true"
,
matchIfMissing
=
true
)
public
static
class
OkHttpClientEnable
{
public
static
class
OkHttpClientEnable
{
/**
/**
* 提供OkHttpClientBean
* 提供OkHttpClientBean
...
@@ -245,7 +242,7 @@ public class BraveAutoConfiguration {
...
@@ -245,7 +242,7 @@ public class BraveAutoConfiguration {
* @param httpTracing
* @param httpTracing
* @return
* @return
*/
*/
@Bean
(
name
=
"techOkHttpClientBuilder"
)
@Bean
(
name
=
"techOkHttpClientBuilder"
)
public
OkHttpClient
.
Builder
okHttpClientBuilder
(
HttpTracing
httpTracing
)
{
public
OkHttpClient
.
Builder
okHttpClientBuilder
(
HttpTracing
httpTracing
)
{
log
.
info
(
"注册braveOkHttpClient.Builder"
);
log
.
info
(
"注册braveOkHttpClient.Builder"
);
return
new
OkHttpClient
.
Builder
()
return
new
OkHttpClient
.
Builder
()
...
@@ -256,9 +253,9 @@ public class BraveAutoConfiguration {
...
@@ -256,9 +253,9 @@ public class BraveAutoConfiguration {
@Configuration
@Configuration
@ConditionalOnClass
(
RestTemplate
.
class
)
@ConditionalOnClass
(
RestTemplate
.
class
)
@ConditionalOnProperty
(
prefix
=
"tech.brave"
,
name
=
"enabled"
,
havingValue
=
"true"
)
@ConditionalOnProperty
(
prefix
=
"tech.brave"
,
name
=
"enabled"
,
havingValue
=
"true"
,
matchIfMissing
=
true
)
@Import
(
TracingClientHttpRequestInterceptor
.
class
)
@Import
(
TracingClientHttpRequestInterceptor
.
class
)
public
static
class
RestTemplateEnable
{
public
static
class
RestTemplateEnable
{
@Autowired
@Autowired
private
TracingClientHttpRequestInterceptor
clientInterceptor
;
private
TracingClientHttpRequestInterceptor
clientInterceptor
;
...
@@ -268,7 +265,7 @@ public class BraveAutoConfiguration {
...
@@ -268,7 +265,7 @@ public class BraveAutoConfiguration {
*
*
* @return
* @return
*/
*/
@Bean
(
name
=
"techRestTemplate"
)
@Bean
(
name
=
"techRestTemplate"
)
public
RestTemplate
restTemplate
()
{
public
RestTemplate
restTemplate
()
{
log
.
info
(
"添加braveRestTemplate拦截器"
);
log
.
info
(
"添加braveRestTemplate拦截器"
);
RestTemplate
restTemplate
=
new
RestTemplate
();
RestTemplate
restTemplate
=
new
RestTemplate
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment