2

Please suggest me what configurations I am missing. My works perfectly when I am running the application locally as a spring-boot jar with mvn spring-boot:run.

But when I try to run the application on external tomcat, I am unable to access swagger UI and swagger end point http://localhost:8090/automation-core/swagger-resources/configuration/ui/.

My steps for running externally are. mvn clean install -U -DskipTests -Pqa (create a war) I am deploying that war on Tomcat 7.62

pom.xml

   <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>swagger-ui</artifactId>
        <version>2.2.10</version>
    </dependency>

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.6.1</version>
        <exclusions>
            <exclusion>
                <artifactId>mapstruct</artifactId>
                <groupId>org.mapstruct</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.6.1</version>
    </dependency>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>swagger-ui</artifactId>
        <version>2.2.10</version>
    </dependency>

    <dependency>
        <groupId>io.swagger</groupId>
        <artifactId>swagger-jaxrs</artifactId>
        <version>1.5.0</version>
        <exclusions>
            <exclusion>
                <artifactId>commons-lang3</artifactId>
                <groupId>org.apache.commons</groupId>
            </exclusion>
            <exclusion>
                <artifactId>swagger-models</artifactId>
                <groupId>io.swagger</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <profile>
            <id>local</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <spring.profiles.active>local</spring.profiles.active>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.apache.tomcat</groupId>
                    <artifactId>tomcat-juli</artifactId>
                    <version>${tomcat.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-devtools</artifactId>
                    <optional>true</optional>
                </dependency>

            </dependencies>
            <build>
                <resources>
                    <resource>
                        <directory>src/main/resources</directory>
                        <filtering>true</filtering>
                    </resource>
                </resources>
            </build>
        </profile>
    <profile>
        <id>qa</id>
        <properties>
            <spring.profiles.active>qa</spring.profiles.active>
        </properties>
        <dependencies>
            <dependency>
                <groupId>org.apache.tomcat</groupId>
                <artifactId>tomcat-dbcp</artifactId>
                <version>7.0.62</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-tomcat</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
        </dependencies>
    </profile>

application.java

    @SpringBootApplication
    @ImportResource({"classpath:springbeans.xml", "classpath:context.xml"})
    @ComponentScan("com.comapany")
    @Configuration
    @PropertySource({"classpath:application.properties","classpath:database.properties", "classpath:authentication.properties","classpath:credentials.properties"})
    @EnableAsync
    @EnableRetry
    @EnableAutoConfiguration
    @EnableMongoRepositories
    @EnableSwagger2
    public class Application extends AsyncConfigurerSupport
    {
        public static void main(String[] args) {
        //System.setProperty("java.awt.headless", "false"); 
        SpringApplication.run(Application.class, args);
    }

    @Bean(name="sVNClient",initMethod="init", destroyMethod="clean")
    public SVNClient sVNClient() {
        return new SVNClient();
    }


    @Override
public Executor getAsyncExecutor()
    {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(2);
        executor.setMaxPoolSize(5);
        executor.setQueueCapacity(100);
        executor.setThreadNamePrefix("webscan-report");
        executor.initialize();
        return executor;
    }
    }

SwaggerConfig.java

@Configuration
@EnableWebMvc
public class SwaggerConfig  extends WebMvcConfigurerAdapter{
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any()).build();
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/swagger-ui/**").addResourceLocations("classpath:/META-INF/resources/webjars/swagger-ui/2.2.10/");
    }

}
rmysari
  • 21
  • 5
  • What's the application context when it runs as a jar and when it runs deployed to an external servlet container? Would it be / when running as a jar with an embedded Tomcat and other than / when running in an external Tomcat? – ootero Oct 11 '17 at 15:18
  • In both cases it should be /automation-core – rmysari Oct 12 '17 at 18:08
  • This may be helpful to you though it didn't solve the problem for me. https://github.com/springfox/springfox/issues/983 – Uncle Long Hair Jan 18 '18 at 19:05
  • I face problem using @EnableWebMvc and Swagger. I resolve the problem removing the annotation and adding the minimal configuration I need. But today, I have the same Issue has you. Maybe we can share our experience to resolve this? – Mohicane Jul 13 '18 at 08:22

0 Answers0