Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
Y
yifu-mvp
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fangxinjiang
yifu-mvp
Commits
528a9343
Commit
528a9343
authored
Jun 01, 2022
by
fangxinjiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
d57c59e6
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
73 additions
and
1360 deletions
+73
-1360
pom.xml
yifu-common/pom.xml
+0
-2
pom.xml
yifu-common/yifu-common-feign/pom.xml
+0
-67
YifuFeignAutoConfiguration.java
...plus.v1/yifu/common/feign/YifuFeignAutoConfiguration.java
+0
-63
EnableYifuFeignClients.java
.../yifu/common/feign/annotation/EnableYifuFeignClients.java
+0
-82
SentinelAutoConfiguration.java
...yifu/common/feign/sentinel/SentinelAutoConfiguration.java
+0
-64
YifuSentinelFeign.java
....v1/yifu/common/feign/sentinel/ext/YifuSentinelFeign.java
+0
-146
YifuSentinelInvocationHandler.java
...mon/feign/sentinel/ext/YifuSentinelInvocationHandler.java
+0
-191
GlobalBizExceptionHandler.java
...mmon/feign/sentinel/handle/GlobalBizExceptionHandler.java
+0
-123
YifuUrlBlockHandler.java
...ifu/common/feign/sentinel/handle/YifuUrlBlockHandler.java
+0
-50
YifuHeaderRequestOriginParser.java
.../feign/sentinel/parser/YifuHeaderRequestOriginParser.java
+0
-46
YifuFeignClientsRegistrar.java
...gframework/cloud/openfeign/YifuFeignClientsRegistrar.java
+0
-240
spring.factories
...common-feign/src/main/resources/META-INF/spring.factories
+0
-4
pom.xml
yifu-common/yifu-common-swagger/pom.xml
+0
-73
EnableYifuDoc.java
...plus.v1/yifu/common/swagger/annotation/EnableYifuDoc.java
+0
-40
SwaggerAutoConfiguration.java
.../yifu/common/swagger/config/SwaggerAutoConfiguration.java
+0
-85
SwaggerProperties.java
...lus.v1/yifu/common/swagger/support/SwaggerProperties.java
+0
-83
pom.xml
yifu-upms/yifu-upms-biz/pom.xml
+6
-1
YifuAdminApplication.java
...m/yifu.cloud.plus.v1/yifu/admin/YifuAdminApplication.java
+3
-0
UserController.java
...u.cloud.plus.v1/yifu/admin/controller/UserController.java
+2
-0
Swagger2Config.java
.../yifu/cloud/plus/v1/yifu/admin/config/Swagger2Config.java
+53
-0
application.yml
yifu-upms/yifu-upms-biz/src/main/resources/application.yml
+9
-0
No files found.
yifu-common/pom.xml
View file @
528a9343
...
...
@@ -38,8 +38,6 @@
<module>
yifu-common-mybatis
</module>
<module>
yifu-common-seata
</module>
<module>
yifu-common-security
</module>
<module>
yifu-common-feign
</module>
<module>
yifu-common-swagger
</module>
<module>
yifu-common-test
</module>
<module>
yifu-common-dapr
</module>
</modules>
...
...
yifu-common/yifu-common-feign/pom.xml
deleted
100644 → 0
View file @
d57c59e6
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2020 yifu4cloud Authors. All Rights Reserved.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<groupId>
com.yifu.cloud.plus.v1
</groupId>
<artifactId>
yifu-common
</artifactId>
<version>
1.0.0
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<packaging>
jar
</packaging>
<artifactId>
yifu-common-feign
</artifactId>
<description>
feign-sentinel服务降级熔断、限流组件
</description>
<dependencies>
<dependency>
<groupId>
com.yifu.cloud.plus.v1
</groupId>
<artifactId>
yifu-common-core
</artifactId>
</dependency>
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
<artifactId>
spring-cloud-starter-alibaba-sentinel
</artifactId>
</dependency>
<!--feign 依赖-->
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-openfeign
</artifactId>
</dependency>
<!-- okhttp 扩展 -->
<dependency>
<groupId>
io.github.openfeign
</groupId>
<artifactId>
feign-okhttp
</artifactId>
</dependency>
<!-- LB 扩展 -->
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-loadbalancer
</artifactId>
</dependency>
<!--caffeine 替换LB 默认缓存实现-->
<dependency>
<groupId>
com.github.ben-manes.caffeine
</groupId>
<artifactId>
caffeine
</artifactId>
</dependency>
<!--oauth server 依赖-->
<dependency>
<groupId>
org.springframework.security
</groupId>
<artifactId>
spring-security-core
</artifactId>
</dependency>
</dependencies>
</project>
yifu-common/yifu-common-feign/src/main/java/com/yifu.cloud.plus.v1/yifu/common/feign/YifuFeignAutoConfiguration.java
deleted
100644 → 0
View file @
d57c59e6
/*
* Copyright (c) 2020 yifu4cloud Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
common
.
feign
;
import
com.alibaba.cloud.sentinel.feign.SentinelFeignAutoConfiguration
;
import
com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler
;
import
com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser
;
import
com.yifu.cloud.plus.v1.yifu.common.feign.sentinel.ext.YifuSentinelFeign
;
import
com.yifu.cloud.plus.v1.yifu.common.feign.sentinel.handle.YifuUrlBlockHandler
;
import
com.yifu.cloud.plus.v1.yifu.common.feign.sentinel.parser.YifuHeaderRequestOriginParser
;
import
feign.Feign
;
import
org.springframework.boot.autoconfigure.AutoConfigureBefore
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Scope
;
/**
* sentinel 配置
*
* @author lengleng
* @date 2020-02-12
*/
@Configuration
(
proxyBeanMethods
=
false
)
@AutoConfigureBefore
(
SentinelFeignAutoConfiguration
.
class
)
public
class
YifuFeignAutoConfiguration
{
@Bean
@Scope
(
"prototype"
)
@ConditionalOnMissingBean
@ConditionalOnProperty
(
name
=
"feign.sentinel.enabled"
)
public
Feign
.
Builder
feignSentinelBuilder
()
{
return
YifuSentinelFeign
.
builder
();
}
@Bean
@ConditionalOnMissingBean
public
BlockExceptionHandler
blockExceptionHandler
()
{
return
new
YifuUrlBlockHandler
();
}
@Bean
@ConditionalOnMissingBean
public
RequestOriginParser
requestOriginParser
()
{
return
new
YifuHeaderRequestOriginParser
();
}
}
yifu-common/yifu-common-feign/src/main/java/com/yifu.cloud.plus.v1/yifu/common/feign/annotation/EnableYifuFeignClients.java
deleted
100644 → 0
View file @
d57c59e6
/*
* Copyright (c) 2020 yifu4cloud Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
common
.
feign
.
annotation
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.cloud.openfeign.FeignClientsConfiguration
;
import
org.springframework.cloud.openfeign.YifuFeignClientsRegistrar
;
import
org.springframework.context.annotation.Import
;
import
java.lang.annotation.*
;
/**
* @author lengleng
* @date 2019/2/1
*/
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@EnableFeignClients
@Import
(
YifuFeignClientsRegistrar
.
class
)
public
@interface
EnableYifuFeignClients
{
/**
* Alias for the {@link #basePackages()} attribute. Allows for more concise annotation
* declarations e.g.: {@code @ComponentScan("org.my.pkg")} instead of
* {@code @ComponentScan(basePackages="org.my.pkg")}.
* @return the array of 'basePackages'.
*/
String
[]
value
()
default
{};
/**
* Base packages to scan for annotated components.
* <p>
* {@link #value()} is an alias for (and mutually exclusive with) this attribute.
* <p>
* Use {@link #basePackageClasses()} for a type-safe alternative to String-based
* package names.
* @return the array of 'basePackages'.
*/
String
[]
basePackages
()
default
{
"com.yifu.cloud.plus.v1"
};
/**
* Type-safe alternative to {@link #basePackages()} for specifying the packages to
* scan for annotated components. The package of each class specified will be scanned.
* <p>
* Consider creating a special no-op marker class or interface in each package that
* serves no purpose other than being referenced by this attribute.
* @return the array of 'basePackageClasses'.
*/
Class
<?>[]
basePackageClasses
()
default
{};
/**
* A custom <code>@Configuration</code> for all feign clients. Can contain override
* <code>@Bean</code> definition for the pieces that make up the client, for instance
* {@link feign.codec.Decoder}, {@link feign.codec.Encoder}, {@link feign.Contract}.
*
* @see FeignClientsConfiguration for the defaults
*/
Class
<?>[]
defaultConfiguration
()
default
{};
/**
* List of classes annotated with @FeignClient. If not empty, disables classpath
* scanning.
* @return
*/
Class
<?>[]
clients
()
default
{};
}
yifu-common/yifu-common-feign/src/main/java/com/yifu.cloud.plus.v1/yifu/common/feign/sentinel/SentinelAutoConfiguration.java
deleted
100644 → 0
View file @
d57c59e6
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
common
.
feign
.
sentinel
;
import
com.alibaba.cloud.sentinel.feign.SentinelFeignAutoConfiguration
;
import
com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler
;
import
com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser
;
import
com.yifu.cloud.plus.v1.yifu.common.feign.sentinel.ext.YifuSentinelFeign
;
import
com.yifu.cloud.plus.v1.yifu.common.feign.sentinel.handle.YifuUrlBlockHandler
;
import
com.yifu.cloud.plus.v1.yifu.common.feign.sentinel.parser.YifuHeaderRequestOriginParser
;
import
feign.Feign
;
import
org.springframework.boot.autoconfigure.AutoConfigureBefore
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Scope
;
/**
* @author lengleng
* @date 2020-02-12
* <p>
* sentinel 配置
*/
@Configuration
(
proxyBeanMethods
=
false
)
@AutoConfigureBefore
(
SentinelFeignAutoConfiguration
.
class
)
public
class
SentinelAutoConfiguration
{
@Bean
@Scope
(
"prototype"
)
@ConditionalOnMissingBean
@ConditionalOnProperty
(
name
=
"feign.sentinel.enabled"
)
public
Feign
.
Builder
feignSentinelBuilder
()
{
return
YifuSentinelFeign
.
builder
();
}
@Bean
@ConditionalOnMissingBean
public
BlockExceptionHandler
blockExceptionHandler
()
{
return
new
YifuUrlBlockHandler
();
}
@Bean
@ConditionalOnMissingBean
public
RequestOriginParser
requestOriginParser
()
{
return
new
YifuHeaderRequestOriginParser
();
}
}
yifu-common/yifu-common-feign/src/main/java/com/yifu.cloud.plus.v1/yifu/common/feign/sentinel/ext/YifuSentinelFeign.java
deleted
100644 → 0
View file @
d57c59e6
/*
* Copyright (c) 2020 yifu4cloud Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
common
.
feign
.
sentinel
.
ext
;
import
com.alibaba.cloud.sentinel.feign.SentinelContractHolder
;
import
feign.Contract
;
import
feign.Feign
;
import
feign.InvocationHandlerFactory
;
import
feign.Target
;
import
org.springframework.beans.BeansException
;
import
org.springframework.cloud.openfeign.FallbackFactory
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.cloud.openfeign.FeignContext
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.core.annotation.AnnotationUtils
;
import
org.springframework.util.ReflectionUtils
;
import
org.springframework.util.StringUtils
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.InvocationHandler
;
import
java.lang.reflect.Method
;
import
java.util.Map
;
/**
* 支持自动降级注入 重写 {@link com.alibaba.cloud.sentinel.feign.SentinelFeign}
*
* @author lengleng
* @date 2020/6/9
*/
public
final
class
YifuSentinelFeign
{
private
YifuSentinelFeign
()
{
}
public
static
YifuSentinelFeign
.
Builder
builder
()
{
return
new
YifuSentinelFeign
.
Builder
();
}
public
static
final
class
Builder
extends
Feign
.
Builder
implements
ApplicationContextAware
{
private
Contract
contract
=
new
Contract
.
Default
();
private
ApplicationContext
applicationContext
;
private
FeignContext
feignContext
;
@Override
public
Feign
.
Builder
invocationHandlerFactory
(
InvocationHandlerFactory
invocationHandlerFactory
)
{
throw
new
UnsupportedOperationException
();
}
@Override
public
YifuSentinelFeign
.
Builder
contract
(
Contract
contract
)
{
this
.
contract
=
contract
;
return
this
;
}
@Override
public
Feign
build
()
{
super
.
invocationHandlerFactory
(
new
InvocationHandlerFactory
()
{
@Override
public
InvocationHandler
create
(
Target
target
,
Map
<
Method
,
MethodHandler
>
dispatch
)
{
// 查找 FeignClient 上的 降级策略
FeignClient
feignClient
=
AnnotationUtils
.
findAnnotation
(
target
.
type
(),
FeignClient
.
class
);
Class
<?>
fallback
=
feignClient
.
fallback
();
Class
<?>
fallbackFactory
=
feignClient
.
fallbackFactory
();
String
beanName
=
feignClient
.
contextId
();
if
(!
StringUtils
.
hasText
(
beanName
))
{
beanName
=
feignClient
.
name
();
}
Object
fallbackInstance
;
FallbackFactory
<?>
fallbackFactoryInstance
;
if
(
void
.
class
!=
fallback
)
{
fallbackInstance
=
getFromContext
(
beanName
,
"fallback"
,
fallback
,
target
.
type
());
return
new
YifuSentinelInvocationHandler
(
target
,
dispatch
,
new
FallbackFactory
.
Default
(
fallbackInstance
));
}
if
(
void
.
class
!=
fallbackFactory
)
{
fallbackFactoryInstance
=
(
FallbackFactory
<?>)
getFromContext
(
beanName
,
"fallbackFactory"
,
fallbackFactory
,
FallbackFactory
.
class
);
return
new
YifuSentinelInvocationHandler
(
target
,
dispatch
,
fallbackFactoryInstance
);
}
return
new
YifuSentinelInvocationHandler
(
target
,
dispatch
);
}
private
Object
getFromContext
(
String
name
,
String
type
,
Class
<?>
fallbackType
,
Class
<?>
targetType
)
{
Object
fallbackInstance
=
feignContext
.
getInstance
(
name
,
fallbackType
);
if
(
fallbackInstance
==
null
)
{
throw
new
IllegalStateException
(
String
.
format
(
"No %s instance of type %s found for feign client %s"
,
type
,
fallbackType
,
name
));
}
if
(!
targetType
.
isAssignableFrom
(
fallbackType
))
{
throw
new
IllegalStateException
(
String
.
format
(
"Incompatible %s instance. Fallback/fallbackFactory of type %s is not assignable to %s for feign client %s"
,
type
,
fallbackType
,
targetType
,
name
));
}
return
fallbackInstance
;
}
});
super
.
contract
(
new
SentinelContractHolder
(
contract
));
return
super
.
build
();
}
private
Object
getFieldValue
(
Object
instance
,
String
fieldName
)
{
Field
field
=
ReflectionUtils
.
findField
(
instance
.
getClass
(),
fieldName
);
field
.
setAccessible
(
true
);
try
{
return
field
.
get
(
instance
);
}
catch
(
IllegalAccessException
e
)
{
// ignore
}
return
null
;
}
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
this
.
applicationContext
=
applicationContext
;
feignContext
=
this
.
applicationContext
.
getBean
(
FeignContext
.
class
);
}
}
}
yifu-common/yifu-common-feign/src/main/java/com/yifu.cloud.plus.v1/yifu/common/feign/sentinel/ext/YifuSentinelInvocationHandler.java
deleted
100644 → 0
View file @
d57c59e6
/*
* Copyright (c) 2020 yifu4cloud Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
common
.
feign
.
sentinel
.
ext
;
import
com.alibaba.cloud.sentinel.feign.SentinelContractHolder
;
import
com.alibaba.cloud.sentinel.feign.SentinelInvocationHandler
;
import
com.alibaba.csp.sentinel.Entry
;
import
com.alibaba.csp.sentinel.EntryType
;
import
com.alibaba.csp.sentinel.SphU
;
import
com.alibaba.csp.sentinel.Tracer
;
import
com.alibaba.csp.sentinel.context.ContextUtil
;
import
com.alibaba.csp.sentinel.slots.block.BlockException
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.R
;
import
feign.Feign
;
import
feign.InvocationHandlerFactory
;
import
feign.MethodMetadata
;
import
feign.Target
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.cloud.openfeign.FallbackFactory
;
import
java.lang.reflect.InvocationHandler
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Proxy
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
static
feign
.
Util
.
checkNotNull
;
/**
* 支持自动降级注入 重写 {@link com.alibaba.cloud.sentinel.feign.SentinelInvocationHandler}
*
* @author lengleng
* @date 2020/6/9
*/
@Slf4j
public
class
YifuSentinelInvocationHandler
implements
InvocationHandler
{
public
static
final
String
EQUALS
=
"equals"
;
public
static
final
String
HASH_CODE
=
"hashCode"
;
public
static
final
String
TO_STRING
=
"toString"
;
private
final
Target
<?>
target
;
private
final
Map
<
Method
,
InvocationHandlerFactory
.
MethodHandler
>
dispatch
;
private
FallbackFactory
<?>
fallbackFactory
;
private
Map
<
Method
,
Method
>
fallbackMethodMap
;
YifuSentinelInvocationHandler
(
Target
<?>
target
,
Map
<
Method
,
InvocationHandlerFactory
.
MethodHandler
>
dispatch
,
FallbackFactory
<?>
fallbackFactory
)
{
this
.
target
=
checkNotNull
(
target
,
"target"
);
this
.
dispatch
=
checkNotNull
(
dispatch
,
"dispatch"
);
this
.
fallbackFactory
=
fallbackFactory
;
this
.
fallbackMethodMap
=
toFallbackMethod
(
dispatch
);
}
YifuSentinelInvocationHandler
(
Target
<?>
target
,
Map
<
Method
,
InvocationHandlerFactory
.
MethodHandler
>
dispatch
)
{
this
.
target
=
checkNotNull
(
target
,
"target"
);
this
.
dispatch
=
checkNotNull
(
dispatch
,
"dispatch"
);
}
@Override
public
Object
invoke
(
final
Object
proxy
,
final
Method
method
,
final
Object
[]
args
)
throws
Throwable
{
if
(
EQUALS
.
equals
(
method
.
getName
()))
{
try
{
Object
otherHandler
=
args
.
length
>
0
&&
args
[
0
]
!=
null
?
Proxy
.
getInvocationHandler
(
args
[
0
])
:
null
;
return
equals
(
otherHandler
);
}
catch
(
IllegalArgumentException
e
)
{
return
false
;
}
}
else
if
(
HASH_CODE
.
equals
(
method
.
getName
()))
{
return
hashCode
();
}
else
if
(
TO_STRING
.
equals
(
method
.
getName
()))
{
return
toString
();
}
Object
result
;
InvocationHandlerFactory
.
MethodHandler
methodHandler
=
this
.
dispatch
.
get
(
method
);
// only handle by HardCodedTarget
if
(
target
instanceof
Target
.
HardCodedTarget
)
{
Target
.
HardCodedTarget
<?>
hardCodedTarget
=
(
Target
.
HardCodedTarget
)
target
;
MethodMetadata
methodMetadata
=
SentinelContractHolder
.
METADATA_MAP
.
get
(
hardCodedTarget
.
type
().
getName
()
+
Feign
.
configKey
(
hardCodedTarget
.
type
(),
method
));
// resource default is HttpMethod:protocol://url
if
(
methodMetadata
==
null
)
{
result
=
methodHandler
.
invoke
(
args
);
}
else
{
String
resourceName
=
methodMetadata
.
template
().
method
().
toUpperCase
()
+
':'
+
hardCodedTarget
.
url
()
+
methodMetadata
.
template
().
path
();
Entry
entry
=
null
;
try
{
ContextUtil
.
enter
(
resourceName
);
entry
=
SphU
.
entry
(
resourceName
,
EntryType
.
OUT
,
1
,
args
);
result
=
methodHandler
.
invoke
(
args
);
}
catch
(
Throwable
ex
)
{
// fallback handle
if
(!
BlockException
.
isBlockException
(
ex
))
{
Tracer
.
trace
(
ex
);
}
if
(
fallbackFactory
!=
null
)
{
try
{
return
fallbackMethodMap
.
get
(
method
).
invoke
(
fallbackFactory
.
create
(
ex
),
args
);
}
catch
(
IllegalAccessException
e
)
{
// shouldn't happen as method is public due to being an
// interface
throw
new
AssertionError
(
e
);
}
catch
(
InvocationTargetException
e
)
{
throw
new
AssertionError
(
e
.
getCause
());
}
}
else
{
// 若是R类型 执行自动降级返回R
if
(
R
.
class
==
method
.
getReturnType
())
{
log
.
error
(
"feign 服务间调用异常"
,
ex
);
return
R
.
failed
(
ex
.
getLocalizedMessage
());
}
else
{
throw
ex
;
}
}
}
finally
{
if
(
entry
!=
null
)
{
entry
.
exit
(
1
,
args
);
}
ContextUtil
.
exit
();
}
}
}
else
{
// other target type using default strategy
result
=
methodHandler
.
invoke
(
args
);
}
return
result
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
obj
instanceof
SentinelInvocationHandler
)
{
YifuSentinelInvocationHandler
other
=
(
YifuSentinelInvocationHandler
)
obj
;
return
target
.
equals
(
other
.
target
);
}
return
false
;
}
@Override
public
int
hashCode
()
{
return
target
.
hashCode
();
}
@Override
public
String
toString
()
{
return
target
.
toString
();
}
static
Map
<
Method
,
Method
>
toFallbackMethod
(
Map
<
Method
,
InvocationHandlerFactory
.
MethodHandler
>
dispatch
)
{
Map
<
Method
,
Method
>
result
=
new
LinkedHashMap
<>();
for
(
Method
method
:
dispatch
.
keySet
())
{
method
.
setAccessible
(
true
);
result
.
put
(
method
,
method
);
}
return
result
;
}
}
yifu-common/yifu-common-feign/src/main/java/com/yifu.cloud.plus.v1/yifu/common/feign/sentinel/handle/GlobalBizExceptionHandler.java
deleted
100644 → 0
View file @
d57c59e6
/*
* Copyright (c) 2020 yifu4cloud Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
common
.
feign
.
sentinel
.
handle
;
import
com.alibaba.csp.sentinel.Tracer
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.R
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.security.access.AccessDeniedException
;
import
org.springframework.security.core.SpringSecurityMessageSource
;
import
org.springframework.util.Assert
;
import
org.springframework.validation.BindException
;
import
org.springframework.validation.FieldError
;
import
org.springframework.web.bind.MethodArgumentNotValidException
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
import
java.util.List
;
/**
* <p>
* 全局异常处理器结合sentinel 全局异常处理器不能作用在 oauth server https://gitee.com/log4j/yifu/issues/I1M2TJ
* </p>
*
* @author lengleng
* @date 2020-06-29
*/
@Slf4j
@Order
(
10000
)
@RestControllerAdvice
@ConditionalOnExpression
(
"!'${security.oauth2.client.clientId}'.isEmpty()"
)
public
class
GlobalBizExceptionHandler
{
/**
* 全局异常.
* @param e the e
* @return R
*/
@ExceptionHandler
(
Exception
.
class
)
@ResponseStatus
(
HttpStatus
.
INTERNAL_SERVER_ERROR
)
public
R
handleGlobalException
(
Exception
e
)
{
log
.
error
(
"全局异常信息 ex={}"
,
e
.
getMessage
(),
e
);
// 业务异常交由 sentinel 记录
Tracer
.
trace
(
e
);
return
R
.
failed
(
e
.
getLocalizedMessage
());
}
/**
* 处理业务校验过程中碰到的非法参数异常 该异常基本由{@link org.springframework.util.Assert}抛出
* @see Assert#hasLength(String, String)
* @see Assert#hasText(String, String)
* @see Assert#isTrue(boolean, String)
* @see Assert#isNull(Object, String)
* @see Assert#notNull(Object, String)
* @param exception 参数校验异常
* @return API返回结果对象包装后的错误输出结果
*/
@ExceptionHandler
(
IllegalArgumentException
.
class
)
@ResponseStatus
(
HttpStatus
.
OK
)
public
R
handleIllegalArgumentException
(
IllegalArgumentException
exception
)
{
log
.
error
(
"非法参数,ex = {}"
,
exception
.
getMessage
(),
exception
);
return
R
.
failed
(
exception
.
getMessage
());
}
/**
* AccessDeniedException
* @param e the e
* @return R
*/
@ExceptionHandler
(
AccessDeniedException
.
class
)
@ResponseStatus
(
HttpStatus
.
FORBIDDEN
)
public
R
handleAccessDeniedException
(
AccessDeniedException
e
)
{
String
msg
=
SpringSecurityMessageSource
.
getAccessor
().
getMessage
(
"AbstractAccessDecisionManager.accessDenied"
,
e
.
getMessage
());
log
.
warn
(
"拒绝授权异常信息 ex={}"
,
msg
);
return
R
.
failed
(
e
.
getLocalizedMessage
());
}
/**
* validation Exception
* @param exception
* @return R
*/
@ExceptionHandler
({
MethodArgumentNotValidException
.
class
})
@ResponseStatus
(
HttpStatus
.
BAD_REQUEST
)
public
R
handleBodyValidException
(
MethodArgumentNotValidException
exception
)
{
List
<
FieldError
>
fieldErrors
=
exception
.
getBindingResult
().
getFieldErrors
();
log
.
warn
(
"参数绑定异常,ex = {}"
,
fieldErrors
.
get
(
0
).
getDefaultMessage
());
return
R
.
failed
(
fieldErrors
.
get
(
0
).
getDefaultMessage
());
}
/**
* validation Exception (以form-data形式传参)
* @param exception
* @return R
*/
@ExceptionHandler
({
BindException
.
class
})
@ResponseStatus
(
HttpStatus
.
BAD_REQUEST
)
public
R
bindExceptionHandler
(
BindException
exception
)
{
List
<
FieldError
>
fieldErrors
=
exception
.
getBindingResult
().
getFieldErrors
();
log
.
warn
(
"参数绑定异常,ex = {}"
,
fieldErrors
.
get
(
0
).
getDefaultMessage
());
return
R
.
failed
(
fieldErrors
.
get
(
0
).
getDefaultMessage
());
}
}
yifu-common/yifu-common-feign/src/main/java/com/yifu.cloud.plus.v1/yifu/common/feign/sentinel/handle/YifuUrlBlockHandler.java
deleted
100644 → 0
View file @
d57c59e6
/*
* Copyright (c) 2020 yifu4cloud Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
common
.
feign
.
sentinel
.
handle
;
import
cn.hutool.http.ContentType
;
import
cn.hutool.json.JSONUtil
;
import
com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler
;
import
com.alibaba.csp.sentinel.slots.block.BlockException
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.R
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.http.HttpStatus
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
/**
* sentinel统一降级限流策略
* <p>
* {@link com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.DefaultBlockExceptionHandler}
*
* @author lengleng
* @date 2020-06-11
*/
@Slf4j
public
class
YifuUrlBlockHandler
implements
BlockExceptionHandler
{
@Override
public
void
handle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
BlockException
e
)
throws
Exception
{
log
.
error
(
"sentinel 降级 资源名称{}"
,
e
.
getRule
().
getResource
(),
e
);
response
.
setContentType
(
ContentType
.
JSON
.
toString
());
response
.
setStatus
(
HttpStatus
.
TOO_MANY_REQUESTS
.
value
());
response
.
getWriter
().
print
(
JSONUtil
.
toJsonStr
(
R
.
failed
(
e
.
getMessage
())));
}
}
yifu-common/yifu-common-feign/src/main/java/com/yifu.cloud.plus.v1/yifu/common/feign/sentinel/parser/YifuHeaderRequestOriginParser.java
deleted
100644 → 0
View file @
d57c59e6
/*
* Copyright (c) 2020 yifu4cloud Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
common
.
feign
.
sentinel
.
parser
;
import
com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser
;
import
javax.servlet.http.HttpServletRequest
;
/**
* sentinel 请求头解析判断
*
* @author lengleng
* @date 2020-06-11
*/
public
class
YifuHeaderRequestOriginParser
implements
RequestOriginParser
{
/**
* 请求头获取allow
*/
private
static
final
String
ALLOW
=
"Allow"
;
/**
* Parse the origin from given HTTP request.
* @param request HTTP request
* @return parsed origin
*/
@Override
public
String
parseOrigin
(
HttpServletRequest
request
)
{
return
request
.
getHeader
(
ALLOW
);
}
}
yifu-common/yifu-common-feign/src/main/java/org/springframework/cloud/openfeign/YifuFeignClientsRegistrar.java
deleted
100644 → 0
View file @
d57c59e6
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package
org
.
springframework
.
cloud
.
openfeign
;
import
com.yifu.cloud.plus.v1.yifu.common.feign.YifuFeignAutoConfiguration
;
import
lombok.Getter
;
import
org.springframework.beans.factory.BeanClassLoaderAware
;
import
org.springframework.beans.factory.config.BeanDefinitionHolder
;
import
org.springframework.beans.factory.support.AbstractBeanDefinition
;
import
org.springframework.beans.factory.support.BeanDefinitionBuilder
;
import
org.springframework.beans.factory.support.BeanDefinitionReaderUtils
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.context.EnvironmentAware
;
import
org.springframework.context.annotation.ImportBeanDefinitionRegistrar
;
import
org.springframework.core.annotation.AnnotatedElementUtils
;
import
org.springframework.core.annotation.AnnotationAttributes
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.io.support.SpringFactoriesLoader
;
import
org.springframework.core.type.AnnotationMetadata
;
import
org.springframework.lang.Nullable
;
import
org.springframework.util.StringUtils
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author L.cm
* @date 2020/2/8
* <p>
* feign 自动配置功能 from mica
*/
public
class
YifuFeignClientsRegistrar
implements
ImportBeanDefinitionRegistrar
,
BeanClassLoaderAware
,
EnvironmentAware
{
@Getter
private
ClassLoader
beanClassLoader
;
@Getter
private
Environment
environment
;
@Override
public
void
registerBeanDefinitions
(
AnnotationMetadata
metadata
,
BeanDefinitionRegistry
registry
)
{
registerFeignClients
(
registry
);
}
@Override
public
void
setBeanClassLoader
(
ClassLoader
classLoader
)
{
this
.
beanClassLoader
=
classLoader
;
}
private
void
registerFeignClients
(
BeanDefinitionRegistry
registry
)
{
List
<
String
>
feignClients
=
SpringFactoriesLoader
.
loadFactoryNames
(
getSpringFactoriesLoaderFactoryClass
(),
getBeanClassLoader
());
// 如果 spring.factories 里为空
if
(
feignClients
.
isEmpty
())
{
return
;
}
for
(
String
className
:
feignClients
)
{
try
{
Class
<?>
clazz
=
beanClassLoader
.
loadClass
(
className
);
AnnotationAttributes
attributes
=
AnnotatedElementUtils
.
getMergedAnnotationAttributes
(
clazz
,
FeignClient
.
class
);
if
(
attributes
==
null
)
{
continue
;
}
// 如果已经存在该 bean,支持原生的 Feign
if
(
registry
.
containsBeanDefinition
(
className
))
{
continue
;
}
registerClientConfiguration
(
registry
,
getClientName
(
attributes
),
attributes
.
get
(
"configuration"
));
validate
(
attributes
);
BeanDefinitionBuilder
definition
=
BeanDefinitionBuilder
.
genericBeanDefinition
(
FeignClientFactoryBean
.
class
);
definition
.
addPropertyValue
(
"url"
,
getUrl
(
attributes
));
definition
.
addPropertyValue
(
"path"
,
getPath
(
attributes
));
String
name
=
getName
(
attributes
);
definition
.
addPropertyValue
(
"name"
,
name
);
// 兼容最新版本的 spring-cloud-openfeign,尚未发布
StringBuilder
aliasBuilder
=
new
StringBuilder
(
18
);
if
(
attributes
.
containsKey
(
"contextId"
))
{
String
contextId
=
getContextId
(
attributes
);
aliasBuilder
.
append
(
contextId
);
definition
.
addPropertyValue
(
"contextId"
,
contextId
);
}
else
{
aliasBuilder
.
append
(
name
);
}
definition
.
addPropertyValue
(
"type"
,
className
);
definition
.
addPropertyValue
(
"decode404"
,
attributes
.
get
(
"decode404"
));
definition
.
addPropertyValue
(
"fallback"
,
attributes
.
get
(
"fallback"
));
definition
.
addPropertyValue
(
"fallbackFactory"
,
attributes
.
get
(
"fallbackFactory"
));
definition
.
setAutowireMode
(
AbstractBeanDefinition
.
AUTOWIRE_BY_TYPE
);
AbstractBeanDefinition
beanDefinition
=
definition
.
getBeanDefinition
();
// alias
String
alias
=
aliasBuilder
.
append
(
"FeignClient"
).
toString
();
// has a default, won't be null
boolean
primary
=
(
Boolean
)
attributes
.
get
(
"primary"
);
beanDefinition
.
setPrimary
(
primary
);
String
qualifier
=
getQualifier
(
attributes
);
if
(
StringUtils
.
hasText
(
qualifier
))
{
alias
=
qualifier
;
}
BeanDefinitionHolder
holder
=
new
BeanDefinitionHolder
(
beanDefinition
,
className
,
new
String
[]
{
alias
});
BeanDefinitionReaderUtils
.
registerBeanDefinition
(
holder
,
registry
);
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
}
}
/**
* Return the class used by {@link SpringFactoriesLoader} to load configuration
* candidates.
* @return the factory class
*/
private
Class
<?>
getSpringFactoriesLoaderFactoryClass
()
{
return
YifuFeignAutoConfiguration
.
class
;
}
private
void
validate
(
Map
<
String
,
Object
>
attributes
)
{
AnnotationAttributes
annotation
=
AnnotationAttributes
.
fromMap
(
attributes
);
// This blows up if an aliased property is overspecified
FeignClientsRegistrar
.
validateFallback
(
annotation
.
getClass
(
"fallback"
));
FeignClientsRegistrar
.
validateFallbackFactory
(
annotation
.
getClass
(
"fallbackFactory"
));
}
private
String
getName
(
Map
<
String
,
Object
>
attributes
)
{
String
name
=
(
String
)
attributes
.
get
(
"serviceId"
);
if
(!
StringUtils
.
hasText
(
name
))
{
name
=
(
String
)
attributes
.
get
(
"name"
);
}
if
(!
StringUtils
.
hasText
(
name
))
{
name
=
(
String
)
attributes
.
get
(
"value"
);
}
name
=
resolve
(
name
);
return
FeignClientsRegistrar
.
getName
(
name
);
}
private
String
getContextId
(
Map
<
String
,
Object
>
attributes
)
{
String
contextId
=
(
String
)
attributes
.
get
(
"contextId"
);
if
(!
StringUtils
.
hasText
(
contextId
))
{
return
getName
(
attributes
);
}
contextId
=
resolve
(
contextId
);
return
FeignClientsRegistrar
.
getName
(
contextId
);
}
private
String
resolve
(
String
value
)
{
if
(
StringUtils
.
hasText
(
value
))
{
return
this
.
environment
.
resolvePlaceholders
(
value
);
}
return
value
;
}
private
String
getUrl
(
Map
<
String
,
Object
>
attributes
)
{
String
url
=
resolve
((
String
)
attributes
.
get
(
"url"
));
return
FeignClientsRegistrar
.
getUrl
(
url
);
}
private
String
getPath
(
Map
<
String
,
Object
>
attributes
)
{
String
path
=
resolve
((
String
)
attributes
.
get
(
"path"
));
return
FeignClientsRegistrar
.
getPath
(
path
);
}
@Nullable
private
String
getQualifier
(
@Nullable
Map
<
String
,
Object
>
client
)
{
if
(
client
==
null
)
{
return
null
;
}
String
qualifier
=
(
String
)
client
.
get
(
"qualifier"
);
if
(
StringUtils
.
hasText
(
qualifier
))
{
return
qualifier
;
}
return
null
;
}
@Nullable
private
String
getClientName
(
@Nullable
Map
<
String
,
Object
>
client
)
{
if
(
client
==
null
)
{
return
null
;
}
String
value
=
(
String
)
client
.
get
(
"contextId"
);
if
(!
StringUtils
.
hasText
(
value
))
{
value
=
(
String
)
client
.
get
(
"value"
);
}
if
(!
StringUtils
.
hasText
(
value
))
{
value
=
(
String
)
client
.
get
(
"name"
);
}
if
(!
StringUtils
.
hasText
(
value
))
{
value
=
(
String
)
client
.
get
(
"serviceId"
);
}
if
(
StringUtils
.
hasText
(
value
))
{
return
value
;
}
throw
new
IllegalStateException
(
"Either 'name' or 'value' must be provided in @"
+
FeignClient
.
class
.
getSimpleName
());
}
private
void
registerClientConfiguration
(
BeanDefinitionRegistry
registry
,
Object
name
,
Object
configuration
)
{
BeanDefinitionBuilder
builder
=
BeanDefinitionBuilder
.
genericBeanDefinition
(
FeignClientSpecification
.
class
);
builder
.
addConstructorArgValue
(
name
);
builder
.
addConstructorArgValue
(
configuration
);
registry
.
registerBeanDefinition
(
name
+
"."
+
FeignClientSpecification
.
class
.
getSimpleName
(),
builder
.
getBeanDefinition
());
}
@Override
public
void
setEnvironment
(
Environment
environment
)
{
this
.
environment
=
environment
;
}
}
yifu-common/yifu-common-feign/src/main/resources/META-INF/spring.factories
deleted
100644 → 0
View file @
d57c59e6
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.yifu.cloud.plus.v1.yifu.common.feign.YifuFeignAutoConfiguration,\
com.yifu.cloud.plus.v1.yifu.common.feign.sentinel.SentinelAutoConfiguration,\
com.yifu.cloud.plus.v1.yifu.common.feign.sentinel.handle.GlobalBizExceptionHandler
yifu-common/yifu-common-swagger/pom.xml
deleted
100644 → 0
View file @
d57c59e6
<?xml version="1.0" encoding="UTF-8"?>
<!--
~
~ Copyright (c) 2018-2025, lengleng All rights reserved.
~
~ Redistribution and use in source and binary forms, with or without
~ modification, are permitted provided that the following conditions are met:
~
~ Redistributions of source code must retain the above copyright notice,
~ this list of conditions and the following disclaimer.
~ Redistributions in binary form must reproduce the above copyright
~ notice, this list of conditions and the following disclaimer in the
~ documentation and/or other materials provided with the distribution.
~ Neither the name of the yifu4cloud.com developer nor the names of its
~ contributors may be used to endorse or promote products derived from
~ this software without specific prior written permission.
~ Author: lengleng (wangiegie@gmail.com)
~
-->
<project
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns=
"http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
com.yifu.cloud.plus.v1
</groupId>
<artifactId>
yifu-common
</artifactId>
<version>
1.0.0
</version>
</parent>
<artifactId>
yifu-common-swagger
</artifactId>
<packaging>
jar
</packaging>
<description>
yifu 接口文档
</description>
<dependencies>
<!--接口文档-->
<dependency>
<groupId>
org.springdoc
</groupId>
<artifactId>
springdoc-openapi-webmvc-core
</artifactId>
</dependency>
<dependency>
<groupId>
org.springdoc
</groupId>
<artifactId>
springdoc-openapi-security
</artifactId>
</dependency>
<dependency>
<groupId>
io.swagger.core.v3
</groupId>
<artifactId>
swagger-annotations
</artifactId>
</dependency>
<!--webflux 相关包-->
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-webflux
</artifactId>
<scope>
provided
</scope>
</dependency>
<!--网关 swagger 聚合依赖-->
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-gateway-server
</artifactId>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-commons
</artifactId>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-webmvc
</artifactId>
<scope>
provided
</scope>
</dependency>
</dependencies>
</project>
yifu-common/yifu-common-swagger/src/main/java/com/yifu.cloud.plus.v1/yifu/common/swagger/annotation/EnableYifuDoc.java
deleted
100644 → 0
View file @
d57c59e6
/*
* Copyright (c) 2020 yifu4cloud Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
common
.
swagger
.
annotation
;
import
com.yifu.cloud.plus.v1.yifu.common.swagger.config.SwaggerAutoConfiguration
;
import
com.yifu.cloud.plus.v1.yifu.common.swagger.support.SwaggerProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Import
;
import
java.lang.annotation.*
;
/**
* 开启 yifu spring doc
*
* @author lengleng
* @date 2022-03-26
*/
@Target
({
ElementType
.
TYPE
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@Inherited
@EnableConfigurationProperties
(
SwaggerProperties
.
class
)
@Import
({
SwaggerAutoConfiguration
.
class
})
public
@interface
EnableYifuDoc
{
}
yifu-common/yifu-common-swagger/src/main/java/com/yifu.cloud.plus.v1/yifu/common/swagger/config/SwaggerAutoConfiguration.java
deleted
100644 → 0
View file @
d57c59e6
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
common
.
swagger
.
config
;
import
com.yifu.cloud.plus.v1.yifu.common.swagger.support.SwaggerProperties
;
import
io.swagger.v3.oas.models.OpenAPI
;
import
io.swagger.v3.oas.models.info.Info
;
import
io.swagger.v3.oas.models.security.OAuthFlow
;
import
io.swagger.v3.oas.models.security.OAuthFlows
;
import
io.swagger.v3.oas.models.security.Scopes
;
import
io.swagger.v3.oas.models.security.SecurityScheme
;
import
io.swagger.v3.oas.models.servers.Server
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.http.HttpHeaders
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* swagger配置
*
* <p>
* 禁用方法1:使用注解@Profile({"dev","test"})
*
* 表示在开发或测试环境开启,而在生产关闭。(推荐使用) 禁用方法2:使用注解@ConditionalOnProperty(name = "swagger.enable",
*
* havingValue = "true") 然后在测试配置或者开发配置中添加swagger.enable=true即可开启,生产环境不填则默认关闭Swagger.
* </p>
*
* @author lengleng
*/
@RequiredArgsConstructor
@ConditionalOnProperty
(
name
=
"swagger.enabled"
,
matchIfMissing
=
true
)
@ConditionalOnMissingClass
(
"org.springframework.cloud.gateway.config.GatewayAutoConfiguration"
)
public
class
SwaggerAutoConfiguration
{
private
final
SwaggerProperties
swaggerProperties
;
private
final
ServiceInstance
serviceInstance
;
@Bean
public
OpenAPI
springOpenAPI
()
{
OpenAPI
openAPI
=
new
OpenAPI
().
info
(
new
Info
().
title
(
swaggerProperties
.
getTitle
()));
// oauth2.0 password
openAPI
.
schemaRequirement
(
HttpHeaders
.
AUTHORIZATION
,
this
.
securityScheme
());
// servers
List
<
Server
>
serverList
=
new
ArrayList
<>();
String
path
=
swaggerProperties
.
getServices
().
get
(
serviceInstance
.
getServiceId
());
serverList
.
add
(
new
Server
().
url
(
swaggerProperties
.
getGateway
()
+
"/"
+
path
));
openAPI
.
servers
(
serverList
);
return
openAPI
;
}
private
SecurityScheme
securityScheme
()
{
OAuthFlow
clientCredential
=
new
OAuthFlow
();
clientCredential
.
setTokenUrl
(
swaggerProperties
.
getTokenUrl
());
clientCredential
.
setScopes
(
new
Scopes
().
addString
(
swaggerProperties
.
getScope
(),
swaggerProperties
.
getScope
()));
OAuthFlows
oauthFlows
=
new
OAuthFlows
();
oauthFlows
.
password
(
clientCredential
);
SecurityScheme
securityScheme
=
new
SecurityScheme
();
securityScheme
.
setType
(
SecurityScheme
.
Type
.
OAUTH2
);
securityScheme
.
setFlows
(
oauthFlows
);
return
securityScheme
;
}
}
yifu-common/yifu-common-swagger/src/main/java/com/yifu.cloud.plus.v1/yifu/common/swagger/support/SwaggerProperties.java
deleted
100644 → 0
View file @
d57c59e6
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the yifu4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
common
.
swagger
.
support
;
import
lombok.Data
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
/**
* SwaggerProperties
*
* @author lengleng
* @date 2018/7/25 14:00
*/
@Data
@ConfigurationProperties
(
"swagger"
)
public
class
SwaggerProperties
{
/**
* 是否开启swagger
*/
private
Boolean
enabled
=
true
;
/**
* swagger会解析的包路径
**/
private
String
basePackage
=
""
;
/**
* swagger会解析的url规则
**/
private
List
<
String
>
basePath
=
new
ArrayList
<>();
/**
* 在basePath基础上需要排除的url规则
**/
private
List
<
String
>
excludePath
=
new
ArrayList
<>();
/**
* 需要排除的服务
*/
private
List
<
String
>
ignoreProviders
=
new
ArrayList
<>();
/**
* 标题
**/
private
String
title
=
""
;
/**
* 网关
*/
private
String
gateway
;
/**
* 获取token
*/
private
String
tokenUrl
;
/**
* 作用域
*/
private
String
scope
;
private
Map
<
String
,
String
>
services
;
}
yifu-upms/yifu-upms-biz/pom.xml
View file @
528a9343
...
...
@@ -55,7 +55,12 @@
<groupId>
com.yifu.cloud.plus.v1
</groupId>
<artifactId>
yifu-common-log
</artifactId>
</dependency>
<!--接口文档-->
<!--接口文档 http://127.0.0.1:4000/swagger-ui/index.html-->
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-boot-starter
</artifactId>
<version>
3.0.0
</version>
</dependency>
<!--<dependency>
<groupId>com.yifu.cloud.plus.v1</groupId>
<artifactId>yifu-common-swagger</artifactId>
...
...
yifu-upms/yifu-upms-biz/src/main/java/com/yifu.cloud.plus.v1/yifu/admin/YifuAdminApplication.java
View file @
528a9343
...
...
@@ -18,7 +18,9 @@ package com.yifu.cloud.plus.v1.yifu.admin;
import
com.yifu.cloud.plus.v1.yifu.common.security.annotation.EnableYifuResourceServer
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
springfox.documentation.oas.annotations.EnableOpenApi
;
/**
* @author lengleng
...
...
@@ -27,6 +29,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
//@EnableYifuDoc
@EnableYifuResourceServer
//@EnableYifuFeignClients
@EnableOpenApi
@SpringBootApplication
public
class
YifuAdminApplication
{
...
...
yifu-upms/yifu-upms-biz/src/main/java/com/yifu.cloud.plus.v1/yifu/admin/controller/UserController.java
View file @
528a9343
...
...
@@ -35,6 +35,7 @@ import com.yifu.cloud.plus.v1.yifu.common.security.annotation.Inner;
import
com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils
;
import
com.pig4cloud.plugin.excel.annotation.RequestExcel
;
import
com.pig4cloud.plugin.excel.annotation.ResponseExcel
;
import
io.swagger.annotations.Api
;
import
io.swagger.v3.oas.annotations.security.SecurityRequirement
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
lombok.RequiredArgsConstructor
;
...
...
@@ -51,6 +52,7 @@ import java.util.Set;
* @author lengleng
* @date 2019/2/1
*/
@Api
(
tags
=
"用户管理模块"
)
@RestController
@RequiredArgsConstructor
@RequestMapping
(
"/user"
)
...
...
yifu-upms/yifu-upms-biz/src/main/java/com/yifu/cloud/plus/v1/yifu/admin/config/Swagger2Config.java
0 → 100644
View file @
528a9343
package
com
.
yifu
.
cloud
.
plus
.
v1
.
yifu
.
admin
.
config
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.config.BeanPostProcessor
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.util.ReflectionUtils
;
import
org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping
;
import
springfox.documentation.spring.web.plugins.WebFluxRequestHandlerProvider
;
import
springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider
;
import
java.lang.reflect.Field
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* @author fxj * @date 2022年05月31日 17:29 @description
*/
@Configuration
public
class
Swagger2Config
{
@Bean
public
static
BeanPostProcessor
springfoxHandlerProviderBeanPostProcessor
()
{
return
new
BeanPostProcessor
()
{
@Override
public
Object
postProcessAfterInitialization
(
Object
bean
,
String
beanName
)
throws
BeansException
{
if
(
bean
instanceof
WebMvcRequestHandlerProvider
||
bean
instanceof
WebFluxRequestHandlerProvider
)
{
customizeSpringfoxHandlerMappings
(
getHandlerMappings
(
bean
));
}
return
bean
;
}
private
<
T
extends
RequestMappingInfoHandlerMapping
>
void
customizeSpringfoxHandlerMappings
(
List
<
T
>
mappings
)
{
List
<
T
>
copy
=
mappings
.
stream
()
.
filter
(
mapping
->
mapping
.
getPatternParser
()
==
null
)
.
collect
(
Collectors
.
toList
());
mappings
.
clear
();
mappings
.
addAll
(
copy
);
}
@SuppressWarnings
(
"unchecked"
)
private
List
<
RequestMappingInfoHandlerMapping
>
getHandlerMappings
(
Object
bean
)
{
try
{
Field
field
=
ReflectionUtils
.
findField
(
bean
.
getClass
(),
"handlerMappings"
);
field
.
setAccessible
(
true
);
return
(
List
<
RequestMappingInfoHandlerMapping
>)
field
.
get
(
bean
);
}
catch
(
IllegalArgumentException
|
IllegalAccessException
e
)
{
throw
new
IllegalStateException
(
e
);
}
}
};
}
}
yifu-upms/yifu-upms-biz/src/main/resources/application.yml
View file @
528a9343
...
...
@@ -38,6 +38,7 @@ ignore:
urls
:
-
/v3/api-docs
-
/actuator/**
-
/swagger-ui/**
# 文件上传相关 支持阿里云、华为云、腾讯、minio
oss
:
...
...
@@ -59,7 +60,11 @@ spring:
application
:
name
:
@
artifactId@
---
spring
:
mvc
:
pathmatch
:
matching-strategy
:
ant_path_matcher
config
:
activate
:
on-profile
:
test
...
...
@@ -73,7 +78,11 @@ spring:
password
:
yf_zsk
url
:
jdbc:mysql://192.168.1.65:22306/yifu_upms?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
---
spring
:
mvc
:
pathmatch
:
matching-strategy
:
ant_path_matcher
config
:
activate
:
on-profile
:
dev
...
...
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