2017-02-28 1 views
1

Je suivais ce document, https://github.com/swagger-api/swagger-core/wiki/1.3--1.5-Migration#setting-up-additional-information-authorization-infoComment ajouter OAuth2 Configuration à Swagger dans undertow java

Dans ce qu'ils demandent d'ajouter servlet bootstrap, Mon problème est que je suis en ajoutant cette classe d'amorçage dans

Ma classe bootstrap

@Override 
    public void init(ServletConfig config) throws ServletException { 
     super.init(config); 



     Info info = new Info() 
       .title("Swagger Petstore") 
       .description("This is a sample server Petstore server. You can find out more about Swagger " + 
         "at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, " + 
         "you can use the api key `special-key` to test the authorization filters.") 
       .termsOfService("http://swagger.io/terms/") 
       .contact(new Contact() 
         .email("[email protected]")) 
       .license(new License() 
         .name("Apache 2.0") 
         .url("http://www.apache.org/licenses/LICENSE-2.0.html")); 

     ServletContext context = config.getServletContext(); 
     Swagger swagger = new Swagger() 
       .info(info); 
     swagger.securityDefinition("testauth", 
       new OAuth2Definition() 
         .implicit("http://localhost:8002/oauth/dialog") 
         .scope("email", "Access to your email address") 
         .scope("pets", "Access to your pets")); 
     swagger.tag(new Tag() 
       .name("pet") 
       .description("Everything about your Pets") 
       .externalDocs(new ExternalDocs("Find out more", "http://swagger.io"))); 
     swagger.tag(new Tag() 
       .name("store") 
       .description("Access to Petstore orders")); 
     swagger.tag(new Tag() 
       .name("user") 
       .description("Operations about user") 
       .externalDocs(new ExternalDocs("Find out more about our store", "http://swagger.io"))); 
     context.setAttribute("swagger", swagger); 
    } 

MON app.class

@ApplicationPath("/") 
    public class App extends javax.ws.rs.core.Application { 


     public App() { 
      this.injector = injector; 
      BeanConfig beanConfig = new BeanConfig(); 
      beanConfig.setVersion("1.0.2"); 
      beanConfig.setSchemes(new String[] { "http" }); 
      beanConfig.setHost("localhost:7004"); 
      beanConfig.setBasePath("test"); 
      beanConfig.setResourcePackage("com.testpacakge"); 
      beanConfig.setScan(true); 
     } 

@Override 
    public Set<Class<?>> getClasses() { 
     Set<Class<?>> resources = new HashSet<Class<?>>(); 
     resources.add(Bootstrap.class); 
/// my other resorces 
} 

@Override 
    public Set<Object> getSingletons() { 
     final Set<Object> objects = new HashSet<>(); 

     objects.add(injector.getInstance(Bootstrap.class)); 
} 
     } 

et dans Main.class

deploymentInfoObj.addServlet(Servlets.servlet("Bootstrap", Bootstrap.class) 
.addMapping("/Bootstrap")); 

J'ajoute le Bootstrap dans, Application et classe principale.

Mais ce paramètre n'est pas chargé pour swagger.

Une idée pour résoudre ce problème?

Répondre

0

Après addition

.setLoadOnStartup(1) 

dans la section Servlet, il fixe

deploymentInfoObj.addServlet(Servlets.servlet("Bootstrap", Bootstrap.class) 
.addMapping("/Bootstrap").setLoadOnStartup(1));