NutzCN Logo
问答 tomcat 部署地址 无法访问 /swagger/swagger.json
发布于 1996天前 作者 JsckChin 5926 次浏览 复制 上一个帖子 下一个帖子
标签:

tomcat 9 配置

<Service name="app">
      
      
      <Connector port="8082" protocol="HTTP/1.1" URIEncoding="UTF-8"
      connectionTimeout="20000"
      redirectPort="8443" /> -->
      
      <!-- Define an AJP 1.3 Connector on port 8009 -->
     <!-- <Connector port="8012" protocol="AJP/1.3" redirectPort="8443" />
      
      <Engine name="app" defaultHost="localhost">
          
          <Realm className="org.apache.catalina.realm.LockOutRealm">
              
              <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
              resourceName="UserDatabase"/>
          </Realm>
          
          <Host name="localhost" appBase="/www/skroot" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false" >
              <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
              prefix="skroot_log" suffix=".txt"
              pattern="%h %l %u %t &quot;%r&quot; %s %b"  />
              <Context path="" docBase="/www/skroot" debug="0" reloadbale="true"/>
          </Host>
      </Engine>
  </Service>
@IocBean(create = "init")
@At("/swagger")
public class SwaggerController {

    private static final Log log = Logs.get();

    protected Swagger swagger;


    @At
    @Ok("void")
    public void swagger(HttpServletRequest request, HttpServletResponse response) throws Exception {
        if ("true".equals(request.getParameter("force")))
            init(); //强制刷新
        final String pathInfo = request.getRequestURI();
        if (pathInfo.endsWith("/swagger.json")) {
            response.setContentType("application/json");
            response.getWriter().println(Json.mapper().writeValueAsString(swagger));
        } else if (pathInfo.endsWith("/swagger.yaml")) {
            response.setContentType("application/yaml");
            response.getWriter().println(Yaml.mapper().writeValueAsString(swagger));
        } else {
            response.setStatus(404);
        }
    }

    public void init() {
        log.info("init swagger ...");
        swagger = new Swagger();

        HashSet<Class<?>> classes = new HashSet<>();
        // 把下来的package路径改成你自己的package路径
        for (Class<?> klass : Scans.me().scanPackage("com.yunqi.modules.open")) {
            classes.add(klass);
        }
        Reader.read(swagger, classes);
    }

}
13 回复
Request URL: http://127.0.0.1:8080/swagger/swagger.json
Request Method: GET
Status Code: 404 
Remote Address: 127.0.0.1:8080
Referrer Policy: no-referrer-when-downgrade

content path是?

2019-05-29 14:31:58,722 org.nutz.mvc.config.AbstractNutConfig.createLoading(AbstractNutConfig.java:62) DEBUG - Loading by class org.nutz.mvc.impl.NutLoading
2019-05-29 14:31:58,725 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:55) INFO  - Nutz Version : 1.r.68-SNAPSHOT 
2019-05-29 14:31:58,726 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:56) INFO  - Nutz.Mvc[nutz] is initializing ...
2019-05-29 14:31:58,726 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:60) DEBUG - Web Container Information:
2019-05-29 14:31:58,737 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:61) DEBUG -  - Default Charset : UTF-8
2019-05-29 14:31:58,737 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:62) DEBUG -  - Current . path  : /Users/YunOu/Downloads/apache-tomcat-9.0.20/bin/.
2019-05-29 14:31:58,738 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:63) DEBUG -  - Java Version    : 1.8.0_101
2019-05-29 14:31:58,738 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:64) DEBUG -  - File separator  : /
2019-05-29 14:31:58,738 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:65) DEBUG -  - Timezone        : Asia/Shanghai
2019-05-29 14:31:58,738 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:66) DEBUG -  - OS              : Mac OS X x86_64
2019-05-29 14:31:58,739 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:67) DEBUG -  - ServerInfo      : Apache Tomcat/9.0.20
2019-05-29 14:31:58,739 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:68) DEBUG -  - Servlet API     : 4.0
2019-05-29 14:31:58,739 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:73) DEBUG -  - ContextPath     : 

ContextPath :
看来部署在根路径, 看看日志里面有没有找到swagger映射吧

有的

2019-05-29 14:31:59,630 org.nutz.mvc.impl.UrlMappingImpl.print(UrlMappingImpl.java:146) DEBUG -    '/swagger/swagger'          >> (SwaggerController.java:35).swagger   : void       | @Ok(void ) @Fail(null ) | by 0 Filters | (I:UTF-8/O:UTF-8)

访问时的日志贴来看看

127.0.0.1 - - [29/May/2019:14:32:12 +0800] "GET /xs HTTP/1.1" 200 10554
127.0.0.1 - - [29/May/2019:14:32:24 +0800] "GET /swagger HTTP/1.1" 302 -
127.0.0.1 - - [29/May/2019:14:32:24 +0800] "GET /swagger/swagger.json HTTP/1.1" 404 1092
127.0.0.1 - - [29/May/2019:14:33:16 +0800] "GET /swagger/swagger HTTP/1.1" 404 1087
127.0.0.1 - - [29/May/2019:14:51:34 +0800] "GET /swagger/swagger.json HTTP/1.1" 404 1092
127.0.0.1 - - [29/May/2019:14:56:35 +0800] "GET /swagger/swagger.json HTTP/1.1" 404 1092
org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:276) DEBUG - batch acquisition of 0 triggers
2019-05-29 14:57:03,133 org.quartz.impl.jdbcjobstore.JobStoreSupport$ClusterManager.manage(JobStoreSupport.java:3877) DEBUG - ClusterManager: Check-in complete.
2019-05-29 14:57:17,871 org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:276) DEBUG - batch acquisition of 0 triggers
2019-05-29 14:57:23,137 org.quartz.impl.jdbcjobstore.JobStoreSupport$ClusterManager.manage(JobStoreSupport.java:3877) DEBUG - ClusterManager: Check-in complete.
2019-05-29 14:57:43,146 org.quartz.impl.jdbcjobstore.JobStoreSupport$ClusterManager.manage(JobStoreSupport.java:3877) DEBUG - ClusterManager: Check-in complete.
2019-05-29 14:57:47,707 org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:276) DEBUG - batch acquisition of 0 triggers

... 就没进项目里面吧

重新下载个新tomcat呗

经测试 tomcat 8,9
加上 @IocBean(create = "init") 无法访问 @At("/docs") 及 @At("/docs/index")

@IocBean(create = "init")
@At("/docs")
public class test {

    private static final Log log = Logs.get();


    @At
    @Ok("void")
    public void index(){
        System.out.println("iindex");
    }
    public void init() {
        log.info("init ...");
      }

}

webapps/docs 目录没删的原因吧

添加回复
请先登陆
回到顶部