-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from LearningGp/mse-simple-demo
Mse simple demo
- Loading branch information
Showing
40 changed files
with
574 additions
and
467 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
mse-simple-demo/A/src/main/java/com/alibabacloud/mse/demo/a/SwaggerBeanPostProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.alibabacloud.mse.demo.a; | ||
|
||
import org.springframework.beans.BeansException; | ||
import org.springframework.beans.factory.config.BeanPostProcessor; | ||
import org.springframework.stereotype.Component; | ||
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; | ||
|
||
@Component | ||
public class SwaggerBeanPostProcessor implements BeanPostProcessor { | ||
@Override | ||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { | ||
if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider) | ||
{ | ||
List<RequestMappingInfoHandlerMapping> handlerMappings = getHandlerMappings(bean); | ||
customizeSpringfoxHandlerMappings(handlerMappings); | ||
} | ||
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); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
mse-simple-demo/A/src/main/java/com/alibabacloud/mse/demo/a/service/FeignClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.alibabacloud.mse.demo.a.service; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
/** | ||
* @author yushan | ||
* @date 2023年02月21日 | ||
*/ | ||
@org.springframework.cloud.openfeign.FeignClient("sc-B") | ||
public interface FeignClient { | ||
|
||
@GetMapping("/bByFeign") | ||
String bByFeign(@RequestParam("s") String s); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.