我目前正在使用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)