https://github.com/joakim666/spring-boot-spring-loaded-java8-example 코드를 참조로 해서 spring loaded와 boot를 써보았다.


아래 pom.xml 를 바탕으로 java8로 셋팅해보았다.

https://github.com/joakim666/spring-boot-spring-loaded-java8-example/blob/master/pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>hello</groupId>
    <artifactId>spring-boot-spring-loaded-java8-example</artifactId>
    <packaging>jar</packaging>
    <version>0.0.1-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.1.4.RELEASE</version>
    </parent>

    <properties>
        <tomcat.version>8.0.8</tomcat.version>
        <!-- use UTF-8 for everything -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.1.2</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <!-- compile for Java 1.8 -->
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <dependencies>
                    <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>springloaded</artifactId>
                        <version>1.2.2.BUILD-SNAPSHOT</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>



내부에서 사용하는 패키지를 사용해서, mvn spring-boot:run를 실행했더니 Unable to start embedded container 에러 가 발생했다. 



Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat

at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:135)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)



문제가 어디서 발생했는지 예상할 수 없었지만, spring-boot 플러그인이 embedded tomcat 기반위에서 실행되기 때문에 tomcat 관련된 lib가 문제가 되지 않을까 확인했다. 

mvn dependency:tree로 확인해보니, jasper가 보였다.


|  +- tomcat:jasper-compiler:jar:5.5.23:runtime

|  +- tomcat:jasper-runtime:jar:5.5.23:runtime



그래서 내부 라이브러리에서 jasper를 사용하는 hadoop,hbase lib를 다음과 같이 제외했다. 


    <dependency>

            <groupId>com.google.adsense</groupId>

            <artifactId>common-google</artifactId>

            <version>2.2.0</version>

            <exclusions>

                <exclusion>

                    <groupId>org.apache.hadoop</groupId>

                    <artifactId>hadoop-common</artifactId>

                </exclusion>

                <exclusion>

                    <groupId>org.apache.hbase</groupId>

                    <artifactId>hbase</artifactId>

                </exclusion>

            </exclusions>

        </dependency>




mvn spring-boot:run을 실행하니. embedded tomcat은 실행되었다. 다만 spring 자동으로 실행되는 AutoConfiguration 클래스에 이슈가 있었고, 실행 에러가 발생했다.


Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.sql.DataSource org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration.dataSource()] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.




다음과 같이 @EnableAutoConfiguration(exclude)를 이용해서 AutoConfiguration 클래스를 제외시켰고

mvn spring-boot:run 실행하니 정상 동작했다.



@Configuration

@ComponentScan

import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;

import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration;

import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;


@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, RabbitAutoConfiguration.class,

        FreeMarkerAutoConfiguration.class})

public class Application {

..

}



참조

http://docs.spring.io/spring-boot/docs/current/reference/html/howto-hotswapping.html

http://docs.spring.io/spring-boot/docs/current/reference/html/howto-embedded-servlet-containers.html

https://github.com/spring-projects/spring-boot/blob/master/spring-boot-dependencies/pom.xml

http://stackoverflow.com/questions/18794573/objc10012-class-javalaunchhelper-is-implemented-in-both-libinstrument-dyl



Posted by '김용환'
,