小编Tek*_*eyy的帖子

无法将Swagger-ui链接到我的Swagger Spring mvc项目

我目前正在使用Eclipse,Spring Framework MVC创建一个API Rest,我刚刚添加到我的项目swagger中.我可以访问swagger的json结果,但我需要添加swagger ui.

以下是我为swagger-springmvc创建的所有文件:

WebAppInitializer.java

public class WebAppInitializer implements WebApplicationInitializer {

    private AnnotationConfigWebApplicationContext ctx = null;

    @Override
    public void onStartup(final ServletContext sc) throws ServletException {

        System.setProperty("spring.profiles.active", "web");

        // Create the 'root' Spring application context
        ctx = new AnnotationConfigWebApplicationContext();
        ctx.register(SpringBaseWebConfiguration.class,
                SpringSwaggerConfiguration.class);

        // Manages the lifecycle
        sc.addListener(new ContextLoaderListener(ctx));
        sc.addListener(new ContextCleanupListener());

        // Spring WebMVC
        ServletRegistration.Dynamic springWebMvc = sc.addServlet("ws",
                new DispatcherServlet(ctx));
        springWebMvc.setLoadOnStartup(1);
        springWebMvc.addMapping("/ws/*");
        springWebMvc.setAsyncSupported(true);
    }

    @PreDestroy
    protected final void cleanup() {
        if (ctx != null) {
            ctx.close();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

SpringSwaggerConfiguration.java

public …
Run Code Online (Sandbox Code Playgroud)

java eclipse spring-mvc swagger swagger-ui

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

eclipse ×1

java ×1

spring-mvc ×1

swagger ×1

swagger-ui ×1