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 "%r" %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);
}
}