我看代码配置有
@IocBean(name="swagger")
public Swagger createSwagger() {
return conf.makeDeep(Swagger.class, "swagger.conf.");
}
如何在application.properties 中设置
swagger.conf.schemes ?
swagger.conf.securityDefinitions ?
这是 swagger json格式
swagger: '2.0'
info:
version: 1.0.0
title: Interface document
schemes:
- https
- http
securityDefinitions:
api_key:
type: apiKey
name: token
in: header
貌似是这样的
Swagger swagger = ioc.get(Swagger.class);
@Override
public void init(ServletConfig config) throws ServletException {
System.out.println("init:: swagger ");
Ioc ioc = appContext.getIoc();
Swagger swagger = ioc.get(Swagger.class);
swagger.setInfo(ioc.get(Info.class, "swaggerInfo"));
HashSet<Class<?>> classes = new HashSet<>();
String pkgName = conf.get("swagger.resource.package", appContext.getPackage());
for (Class<?> klass : Scans.me().scanPackage(pkgName)) {
classes.add(klass);
}
Reader.read(swagger, classes);
config.getServletContext().setAttribute("swagger", swagger);
}
swagger.conf.schemes=http,https 这样写不行
[DEBUG] 12:45:34.120 org.nutz.ioc.impl.ScopeContext.remove(ScopeContext.java:85) - Remove object 'swagger' from [app]
[WARN ] 12:45:34.121 org.eclipse.jetty.server.handler.ContextHandler$Context.log(ContextHandler.java:2230) - unavailable
org.nutz.ioc.IocException: IocBean[swagger] throw Exception when creating
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:153)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:271)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:161)
at com.yunqi.nt.common.starter.SwaggerServletStarter.init(SwaggerServletStarter.java:82)
at org.eclipse.jetty.servlet.ServletHolder$WrapperServlet.init(ServletHolder.java:1287)
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:599)
at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:425)
at org.eclipse.jetty.servlet.ServletHandler.lambda$initialize$0(ServletHandler.java:751)
at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:357)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:312)
at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:735)
at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:734)
at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658)
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:744)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:361)
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1443)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1407)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:821)
at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:276)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:524)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:169)
at org.eclipse.jetty.server.Server.start(Server.java:407)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:110)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:106)
at org.eclipse.jetty.server.Server.doStart(Server.java:371)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
at org.nutz.boot.starter.jetty.JettyStarter.start(JettyStarter.java:160)
at org.nutz.boot.AppContext.startServers(AppContext.java:310)
at org.nutz.boot.NbApp.execute(NbApp.java:210)
at org.nutz.boot.NbApp.run(NbApp.java:182)
at com.yunqi.nt.common.core.MainLauncher.main(MainLauncher.java:63)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:282)
at java.base/java.lang.Thread.run(Thread.java:830)
在 MainLauncher init 方法中,这样写可以
List<Scheme> schemes = new ArrayList<>();
schemes.add(Scheme.HTTP);
schemes.add(Scheme.HTTPS);
swagger.setSchemes(schemes);
// swagger 配置
List<Scheme> schemes = new ArrayList<>();
schemes.add(Scheme.HTTP);
schemes.add(Scheme.HTTPS);
swagger.setSchemes(schemes);
Map<String, SecuritySchemeDefinition> definition = new HashMap<>();
definition.put("api_key", new ApiKeyAuthDefinition("token", In.HEADER));
swagger.setSecurityDefinitions(definition);