关于授权服务引入 mms-common 通用模块 Nacos 异常问题排查

一、引入mms-common常量服务

mms-authdemo/pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>
        <artifactId>model-management</artifactId>
        <groupId>com.homay</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>mms-authdemo</artifactId>
    <dependencies>

        <dependency>
            <groupId>com.homay</groupId>
            <artifactId>mms-common</artifactId>
            <version>1.0-SNAPSHOT</version>
            <exclusions>
                <exclusion>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-jdbc</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.baomidou</groupId>
                    <artifactId>mybatis-plus-boot-starter</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.alibaba</groupId>
                    <artifactId>druid-spring-boot-starter</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.alibaba.cloud</groupId>
                    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-starter-oauth2</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- 服务的注册中心 -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>

        <!--  资源服务器 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-oauth2</artifactId>
        </dependency>

        <!-- web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

</project>

引入通用模块的依赖,排除了nacos配置中心:

<?xml version="1.0" encoding="UTF-8"?>
<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>
        <artifactId>model-management</artifactId>
        <groupId>com.homay</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>mms-authdemo</artifactId>
    <dependencies>

        <dependency>
            <groupId>com.homay</groupId>
            <artifactId>mms-common</artifactId>
            <version>1.0-SNAPSHOT</version>
            <exclusions>
                <exclusion>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-jdbc</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.baomidou</groupId>
                    <artifactId>mybatis-plus-boot-starter</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.alibaba</groupId>
                    <artifactId>druid-spring-boot-starter</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.alibaba.cloud</groupId>
                    <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

</project>

file

可以正常启动了

使用POSTman也可以获取到JWTTOKEN了

file

启动成功之后的日志打印:

 .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.2.RELEASE)

2021-07-27 12:39:19.995  INFO 20276 --- [           main] com.homay.authdemo.AuthdemoApplication   : The following profiles are active: local
2021-07-27 12:39:21.181  INFO 20276 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2021-07-27 12:39:21.184  INFO 20276 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2021-07-27 12:39:21.222  INFO 20276 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 18ms. Found 0 Redis repository interfaces.
2021-07-27 12:39:21.303  WARN 20276 --- [           main] o.s.boot.actuate.endpoint.EndpointId     : Endpoint ID 'service-registry' contains invalid characters, please migrate to a valid format.
2021-07-27 12:39:21.481  INFO 20276 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=4846d6d9-9fe2-3412-be16-1ab1eef4d8b2
2021-07-27 12:39:21.869  INFO 20276 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8888 (http)
2021-07-27 12:39:21.880  INFO 20276 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-07-27 12:39:21.880  INFO 20276 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.37]
2021-07-27 12:39:22.059  INFO 20276 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-07-27 12:39:22.059  INFO 20276 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2037 ms
2021-07-27 12:39:22.530  WARN 20276 --- [           main] c.n.c.sources.URLConfigurationSource     : No URLs will be polled as dynamic configuration sources.
2021-07-27 12:39:22.530  INFO 20276 --- [           main] c.n.c.sources.URLConfigurationSource     : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2021-07-27 12:39:22.535  WARN 20276 --- [           main] c.n.c.sources.URLConfigurationSource     : No URLs will be polled as dynamic configuration sources.
2021-07-27 12:39:22.535  INFO 20276 --- [           main] c.n.c.sources.URLConfigurationSource     : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2021-07-27 12:39:22.684  INFO 20276 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-07-27 12:39:23.395  INFO 20276 --- [           main] o.s.s.c.ThreadPoolTaskScheduler          : Initializing ExecutorService 'Nacos-Watch-Task-Scheduler'
2021-07-27 12:39:24.290  INFO 20276 --- [           main] o.s.s.web.DefaultSecurityFilterChain     : Creating filter chain: OrRequestMatcher [requestMatchers=[Ant [pattern='/oauth/token'], Ant [pattern='/oauth/token_key'], Ant [pattern='/oauth/check_token']]], [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@6f1fa1d0, org.springframework.security.web.context.SecurityContextPersistenceFilter@7e3d2ebd, org.springframework.security.web.header.HeaderWriterFilter@2bec068b, org.springframework.security.web.authentication.logout.LogoutFilter@7d37ee0c, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@5012c571, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@3a4a5f3c, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@4aaecabd, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@28b523a, org.springframework.security.web.session.SessionManagementFilter@28d739f1, org.springframework.security.web.access.ExceptionTranslationFilter@2eb0cefe, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@7a606260]
2021-07-27 12:39:24.299  INFO 20276 --- [           main] o.s.s.web.DefaultSecurityFilterChain     : Creating filter chain: org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfiguration$NotOAuthRequestMatcher@6ad6443, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@78b03788, org.springframework.security.web.context.SecurityContextPersistenceFilter@58d4238e, org.springframework.security.web.header.HeaderWriterFilter@1eeb5818, org.springframework.security.web.authentication.logout.LogoutFilter@75793f17, org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter@2c48cede, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@72a8361b, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@36478bce, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@3f5dfe69, org.springframework.security.web.session.SessionManagementFilter@44dfdd58, org.springframework.security.web.access.ExceptionTranslationFilter@29d070c7, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@32ab408e]
2021-07-27 12:39:24.300  INFO 20276 --- [           main] o.s.s.web.DefaultSecurityFilterChain     : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@194012a2, org.springframework.security.web.context.SecurityContextPersistenceFilter@7b6141f0, org.springframework.security.web.header.HeaderWriterFilter@497ed877, org.springframework.security.web.authentication.logout.LogoutFilter@a91119b, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@4fb64a52, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@70b48eb3, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@55296b50, org.springframework.security.web.session.SessionManagementFilter@3cb6e0ee, org.springframework.security.web.access.ExceptionTranslationFilter@451e2fa9, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@2f0ccb34]
2021-07-27 12:39:24.950  WARN 20276 --- [           main] s.o.SpringCloudSecurityAutoConfiguration : All Spring Cloud Security modules and starters are deprecated. They will be moved to individual projects in the next major release.
2021-07-27 12:39:24.953  INFO 20276 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 2 endpoint(s) beneath base path '/actuator'
2021-07-27 12:39:25.146  INFO 20276 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8888 (http) with context path ''
2021-07-27 12:39:25.159  INFO 20276 --- [           main] c.a.c.n.registry.NacosServiceRegistry    : nacos registry, local mms-auth 192.168.74.1:8888 register finished
2021-07-27 12:39:25.744  INFO 20276 --- [           main] com.homay.authdemo.AuthdemoApplication   : Started AuthdemoApplication in 8.63 seconds (JVM running for 10.986)
2021-07-27 12:39:26.677  INFO 20276 --- [-192.168.10.160] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-07-27 12:39:26.677  INFO 20276 --- [-192.168.10.160] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2021-07-27 12:39:26.682  INFO 20276 --- [-192.168.10.160] o.s.web.servlet.DispatcherServlet        : Completed initialization in 5 ms

可以看到最核心的日志输出:

Creating filter chain: OrRequestMatcher [requestMatchers=[Ant [pattern='/oauth/token'], Ant [pattern='/oauth/token_key'], Ant [pattern='/oauth/check_token']]], [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@6f1fa1d0,

为者常成,行者常至