Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring boot招摇过市用户界面在Ngnix后不工作_Java_Spring Boot_Nginx_Tomcat_Swagger - Fatal编程技术网

Java Spring boot招摇过市用户界面在Ngnix后不工作

Java Spring boot招摇过市用户界面在Ngnix后不工作,java,spring-boot,nginx,tomcat,swagger,Java,Spring Boot,Nginx,Tomcat,Swagger,这些是我目前用来配置swagger的配置,但它没有加载API 我尝试过的事情 将spring boot和spring fox版本更改为最新版本 使用上下文路径更改了nginx服务器块中的位置 将代理传递设置为精确的端口号 在swagger配置中添加了协议 Ngnix会议: map $http_origin $cors_header { default ""; "~^https?://[^/]+\.example\.com(:[0-9]

这些是我目前用来配置swagger的配置,但它没有加载API

我尝试过的事情 将spring boot和spring fox版本更改为最新版本

使用上下文路径更改了nginx服务器块中的位置

将代理传递设置为精确的端口号

在swagger配置中添加了协议

Ngnix会议:

map $http_origin $cors_header {
        default "";
        "~^https?://[^/]+\.example\.com(:[0-9]+)?$" "$http_origin";
     }

server {
    listen 80;
    server_name document.example.com www.document.example.com;
    if ($http_x_forwarded_proto = 'http'){
           return 301 https://$host$request_uri;
        }
    access_log /var/log/nginx/ims_access.log;
    error_log /var/log/nginx/ims_error.log;

        root /usr/share/nginx/iapi;
        index index.php index.html index.htm;

         location / {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
            proxy_redirect off;
            proxy_connect_timeout      240;
            proxy_send_timeout         240;
            proxy_read_timeout         240;
            proxy_set_header Scheme $scheme;
            proxy_http_version 1.1;
            proxy_pass http://127.0.0.1:8050/;
        }


        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;

        location ~ /\.(svn|git) {
                deny all;
        }


        location ~ \.php$ {
          try_files $uri =404;
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          fastcgi_pass unix:/run/php/php7.2-fpm.sock;
          fastcgi_index index.php;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_buffer_size 128k;
          fastcgi_buffers 256 16k;
          fastcgi_busy_buffers_size 256k;
          fastcgi_temp_file_write_size 256k;
        }

    }
@Configuration
@Profile({ "dev", "stage" })
@EnableSwagger2
public class SwaggerConfiguration {
    @Bean
    public Docket api() {
        HashSet<String> hashSet = new HashSet<String>();
        hashSet.add("http");
        hashSet.add("https");
        return new Docket(DocumentationType.SWAGGER_2).select()
                .apis(RequestHandlerSelectors.basePackage("com.example.customer.rest_endpoints"))
                .paths(PathSelectors.any()).build().apiInfo(apiEndPointsInfo())
                .globalOperationParameters(getImplicitPrams()).useDefaultResponseMessages(false)
                .globalResponseMessage(RequestMethod.GET, getResponseMessages())
                .globalResponseMessage(RequestMethod.POST, getResponseMessages())
                .protocols(hashSet)
                .pathMapping("/");
    }

    private ApiInfo apiEndPointsInfo() {
        return new ApiInfoBuilder().title("CustomerApp APIs").description("Customer Application API")
                .contact(new Contact("Hemanta Singh", "www.example.com", "hemanta.singh@example.com"))
                .build();

    }

    private java.util.List<ResponseMessage> getResponseMessages() {
        java.util.List<ResponseMessage> list = new ArrayList<>();
        list.add(new ResponseMessageBuilder().code(200).message("request processed").build());
        list.add(new ResponseMessageBuilder().code(201).message("something went wrong").build());
        list.add(new ResponseMessageBuilder().code(401).message("Unauthorized").build());
        list.add(new ResponseMessageBuilder().code(500).message("Internal Server Error").build());
        list.add(new ResponseMessageBuilder().code(403).message("Not allowed").build());
        list.add(new ResponseMessageBuilder().code(409).message("Duplicate Request").build());
        return list;

    }

    private java.util.List<Parameter> getImplicitPrams() {
        java.util.List<Parameter> aParameters = new ArrayList<Parameter>();
        aParameters.add(new ParameterBuilder().name("sessionId").modelRef(new ModelRef("string"))
                .parameterType("header").defaultValue("12476152srasytdhas").build());
        aParameters.add(new ParameterBuilder().name("mobile").modelRef(new ModelRef("string")).parameterType("header")
                .defaultValue("9080562341").build());
        return aParameters;

    }

}

buildscript {
    ext {
        springBootVersion = '2.2.4.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'

group = 'com.example.customer'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

configurations {
    providedRuntime
    all*.exclude module : 'spring-boot-starter-logging'
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-cache')
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
     {
        exclude group:'org.glassfish', module:'javax.el'
    }
    
    compile('org.springframework.boot:spring-boot-starter-web')
     {
      exclude group:'org.glassfish', module:'javax.el'
    }
    compile ('org.springframework.boot:spring-boot-starter-mail')
    compile('org.springframework.boot:spring-boot-starter-web')

       
     //exclude group:'org.glassfish', module:'javax.el';
       // exclude module : 'spring-boot-starter-logging'
       // https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api
    compile('org.glassfish:javax.el:3.0.1-b08')
    runtime('com.h2database:h2')
    runtime('mysql:mysql-connector-java')
    providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    compile('com.googlecode.xmemcached:xmemcached:1.2.5')
    compile('com.google.api-client:google-api-client:1.23.0')
    compile('com.google.firebase:firebase-admin:6.0.0')
    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    compile('org.xhtmlrenderer:flying-saucer-core:9.1.4')
    compile('org.xhtmlrenderer:flying-saucer-pdf-itext5:9.1.4')
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile('joda-time:joda-time:2.9.7')
    compile('com.squareup.retrofit2:retrofit:2.3.0')
    compile('com.squareup.okhttp3:okhttp:3.10.0')
    compile('org.apache.commons:commons-lang3:3.0')
    compile ('com.razorpay:razorpay-java:1.3.8')
    compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
    compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'
    // https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-ui
    //compile group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.4.8'

}


招摇过市配置:

map $http_origin $cors_header {
        default "";
        "~^https?://[^/]+\.example\.com(:[0-9]+)?$" "$http_origin";
     }

server {
    listen 80;
    server_name document.example.com www.document.example.com;
    if ($http_x_forwarded_proto = 'http'){
           return 301 https://$host$request_uri;
        }
    access_log /var/log/nginx/ims_access.log;
    error_log /var/log/nginx/ims_error.log;

        root /usr/share/nginx/iapi;
        index index.php index.html index.htm;

         location / {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
            proxy_redirect off;
            proxy_connect_timeout      240;
            proxy_send_timeout         240;
            proxy_read_timeout         240;
            proxy_set_header Scheme $scheme;
            proxy_http_version 1.1;
            proxy_pass http://127.0.0.1:8050/;
        }


        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;

        location ~ /\.(svn|git) {
                deny all;
        }


        location ~ \.php$ {
          try_files $uri =404;
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          fastcgi_pass unix:/run/php/php7.2-fpm.sock;
          fastcgi_index index.php;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_buffer_size 128k;
          fastcgi_buffers 256 16k;
          fastcgi_busy_buffers_size 256k;
          fastcgi_temp_file_write_size 256k;
        }

    }
@Configuration
@Profile({ "dev", "stage" })
@EnableSwagger2
public class SwaggerConfiguration {
    @Bean
    public Docket api() {
        HashSet<String> hashSet = new HashSet<String>();
        hashSet.add("http");
        hashSet.add("https");
        return new Docket(DocumentationType.SWAGGER_2).select()
                .apis(RequestHandlerSelectors.basePackage("com.example.customer.rest_endpoints"))
                .paths(PathSelectors.any()).build().apiInfo(apiEndPointsInfo())
                .globalOperationParameters(getImplicitPrams()).useDefaultResponseMessages(false)
                .globalResponseMessage(RequestMethod.GET, getResponseMessages())
                .globalResponseMessage(RequestMethod.POST, getResponseMessages())
                .protocols(hashSet)
                .pathMapping("/");
    }

    private ApiInfo apiEndPointsInfo() {
        return new ApiInfoBuilder().title("CustomerApp APIs").description("Customer Application API")
                .contact(new Contact("Hemanta Singh", "www.example.com", "hemanta.singh@example.com"))
                .build();

    }

    private java.util.List<ResponseMessage> getResponseMessages() {
        java.util.List<ResponseMessage> list = new ArrayList<>();
        list.add(new ResponseMessageBuilder().code(200).message("request processed").build());
        list.add(new ResponseMessageBuilder().code(201).message("something went wrong").build());
        list.add(new ResponseMessageBuilder().code(401).message("Unauthorized").build());
        list.add(new ResponseMessageBuilder().code(500).message("Internal Server Error").build());
        list.add(new ResponseMessageBuilder().code(403).message("Not allowed").build());
        list.add(new ResponseMessageBuilder().code(409).message("Duplicate Request").build());
        return list;

    }

    private java.util.List<Parameter> getImplicitPrams() {
        java.util.List<Parameter> aParameters = new ArrayList<Parameter>();
        aParameters.add(new ParameterBuilder().name("sessionId").modelRef(new ModelRef("string"))
                .parameterType("header").defaultValue("12476152srasytdhas").build());
        aParameters.add(new ParameterBuilder().name("mobile").modelRef(new ModelRef("string")).parameterType("header")
                .defaultValue("9080562341").build());
        return aParameters;

    }

}

buildscript {
    ext {
        springBootVersion = '2.2.4.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'

group = 'com.example.customer'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

configurations {
    providedRuntime
    all*.exclude module : 'spring-boot-starter-logging'
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-cache')
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
     {
        exclude group:'org.glassfish', module:'javax.el'
    }
    
    compile('org.springframework.boot:spring-boot-starter-web')
     {
      exclude group:'org.glassfish', module:'javax.el'
    }
    compile ('org.springframework.boot:spring-boot-starter-mail')
    compile('org.springframework.boot:spring-boot-starter-web')

       
     //exclude group:'org.glassfish', module:'javax.el';
       // exclude module : 'spring-boot-starter-logging'
       // https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api
    compile('org.glassfish:javax.el:3.0.1-b08')
    runtime('com.h2database:h2')
    runtime('mysql:mysql-connector-java')
    providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    compile('com.googlecode.xmemcached:xmemcached:1.2.5')
    compile('com.google.api-client:google-api-client:1.23.0')
    compile('com.google.firebase:firebase-admin:6.0.0')
    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    compile('org.xhtmlrenderer:flying-saucer-core:9.1.4')
    compile('org.xhtmlrenderer:flying-saucer-pdf-itext5:9.1.4')
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile('joda-time:joda-time:2.9.7')
    compile('com.squareup.retrofit2:retrofit:2.3.0')
    compile('com.squareup.okhttp3:okhttp:3.10.0')
    compile('org.apache.commons:commons-lang3:3.0')
    compile ('com.razorpay:razorpay-java:1.3.8')
    compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
    compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'
    // https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-ui
    //compile group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.4.8'

}


从nginx错误日志``29 connect()在连接到上游时失败(111:连接被拒绝),客户端:…**.**,服务器:document.example.com,请求:“GET/example customer/swagger resources/configuration/ui HTTP/1.1”,上游:,主机:“document.example.com”,参考者:“```