【问题标题】:Whitelabel Error page, Type:Not Found Status:404Whitelabel 错误页面,类型:未找到状态:404
【发布时间】:2019-04-16 15:37:59
【问题描述】:

我们最近将 Spring Boot 版本从 1.5.10 升级到了 2.1.2,但我遇到了一个问题。当服务部署在 j boss 服务器上时,当我通过 https://host:port/serviceName/swagger-ui.html 大摇大摆地调用服务时,它显示服务未找到并抛出白标签错误页面的错误,但如果我调用 https://host:port/swagger-ui.html 我可以访问该服务和所有内容工作正常。有人可以让我知道会是什么问题。感谢您的帮助。

pom.xml 或 bootstrap.yml 没有任何变化,我刚刚升级了 spring boot 版本。其他都和以前一样。

下面是 POM.Xml

<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">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.goo.foo</groupId>
    <artifactId>security-service</artifactId>
    <version>1.2.3</version>
    <properties>
        <dep.scope>compile</dep.scope>
        <java.version>1.8</java.version>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.source>1.8</maven.compiler.source>
        <ojdbc.version>12.1.0.2</ojdbc.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <springfox-version>2.6.1</springfox-version>
        <config.version>2.1.0.RELEASE</config.version>
        <admin.version>2.1.0</admin.version>
        <consul-starter.version>2.1.0.RELEASE</consul-starter.version>
        <cloud-consul.version>2.1.0.RELEASE</cloud-consul.version>
    </properties>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
        <relativePath />
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-consul-dependencies</artifactId>
            <version>${cloud-consul.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <!--SpringFox dependencies -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${springfox-version}</version>
            <scope>${dep.scope}</scope>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>${springfox-version}</version>
            <scope>${dep.scope}</scope>
        </dependency>
        <dependency>
            <groupId>org.owasp.esapi</groupId>
            <artifactId>esapi</artifactId>
            <version>2.1.0</version>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.7.0</version>
        </dependency>
        <!-- Oracle JDBC driver -->
        <dependency>
            <groupId>com.oracle.jdbc</groupId>
            <artifactId>ojdbc7</artifactId>
            <version>${ojdbc.version}</version>
            <scope>${dep.scope}</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
        </dependency>
        <!-- Consul properties -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-consul-all</artifactId>
            <version>${consul-starter.version}</version>
        </dependency>
        <!-- Spring config server - external properties -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-client</artifactId>
            <version>${config.version}</version>
        </dependency>

        <!-- Spring boot admin client - monitoring the purpose -->
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
            <version>${admin.version}</version>
        </dependency>

    <!--  jedis cache  -->
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

【问题讨论】:

    标签: maven spring-boot java-8 swagger-2.0


    【解决方案1】:

    好像你“丢失”了你的context-path。我猜您之前以某种形式使用现已弃用的server.contextPath=/serviceName 指定了它。有几种设置方法,但我的做法是在application.yaml中配置它

    server:
      servlet:
        context-path: serviceName
    

    application.properties

    server.servlet.context-path=/serviceName
    

    或者您可以通过将其指定为命令行参数来设置上下文路径

    java -jar app.jar --server.servlet.context-path=/serviceName
    

    这只是一些可用的选项。弄清楚你之前是如何设置的,然后用server.servlet.context-path替换它

    【讨论】:

    • 在我的 bootstrap.yml 中有一个带有 feild "spring: application: name:" 的属性,它会检查应用程序名称。
    • 我会尝试 server: servlet: context-path: serviceName 专门设置 context-path 看看是否有效
    猜你喜欢
    • 2018-08-08
    • 2016-07-28
    • 2020-10-30
    • 2020-03-04
    • 1970-01-01
    • 2021-06-19
    • 2021-09-24
    • 1970-01-01
    • 2017-10-06
    相关资源
    最近更新 更多