LoginSignup
3
4

More than 5 years have passed since last update.

MSF4JとSpringBootを比較してみた その1(Jarファイルサイズ編)

Last updated at Posted at 2016-04-10

WSO2からMicroServices用のフレームワークが出ており、前々から気になっていたので試し始めました。
んで、自分がよく使っているSpringBootと比較をしてみたいと思います。
MSF4J
SpringBoot

MSF4J側の準備

チュートリアルに従って、インストールしてみる。まずはプロジェクト作成。

プロジェクト作成

mvn archetype:generate -DarchetypeGroupId=org.wso2.msf4j \
-DarchetypeArtifactId=msf4j-microservice -DarchetypeVersion=1.0.0 \
-DgroupId=org.example -DartifactId=Hello-Service -Dversion=1.0.0-SNAPSHOT \
-Dpackage=org.example.service -DserviceClass=HelloService

きれいにpom.xmlまで出来上がりました。

<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">

    <parent>
        <groupId>org.wso2.msf4j</groupId>
        <artifactId>msf4j-service</artifactId>
        <version>1.0.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>Hello-Service</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <name>WSO2 MSF4J Microservice</name>


    <dependencies>
    <!-- Uncomment the following if you want to enable metrics & monitoring -->
    <!--
    <dependency>
       <groupId>org.wso2.msf4j</groupId>
       <artifactId>msf4j-analytics</artifactId>
    </dependency>
    -->
    </dependencies>

    <properties>
        <microservice.mainClass>org.example.service.Application</microservice.mainClass>
    </properties>

</project>

ソース準備

今回はSpringBootとのJarファイルサイズの比較をしたいので、getのメソッド以外はコメントアウトしておきます。

@Path("/service")
public class HelloService {

    @GET
    @Path("/")
    public String get() {
        return "Hello from WSO2 MSF4J";
    }

}

いざ、ビルド

mvn package

でJarファイルの作成

targetフォルダ配下にこんな感じで出力されました。

5227309  4  4 03:21 Hello-Service-1.0.0-SNAPSHOT.jar

気になるJarファイルサイズは約5.2MBでした。

念のため動作確認

一応出来上がったJarファイルが動くことを確認しました。

$ java -jar Hello-Service-1.0.0-SNAPSHOT.jar 
2016-04-04 03:36:01 INFO  MicroservicesRegistry:76 - Added microservice: org.example.service.HelloService@443b7951
2016-04-04 03:36:01 INFO  NettyListener:56 - Starting Netty Http Transport Listener
2016-04-04 03:36:01 INFO  NettyListener:80 - Netty Listener starting on port 8080
2016-04-04 03:36:01 INFO  MicroservicesRunner:122 - Microservices server started in 278ms

ソースにあった通りのURLにアクセスしてみます。

$ curl http://localhost:8080/service/
Hello from WSO2 MSF4Ji

問題なく動いていますね。

SpringBoot側の準備

では次に、SpringBoot側も準備をします。

プロジェクト作成

同様にプロジェクトの作成から。

mvn archetype:generate -DgroupId=jp.gr.java_conf.kojiisd -DartifactId=spring_boot_sample

pom.xmlに編集を加えます。不要なJUnitは今回削除し、以下のようにspring−boot-starter-webを追加します。

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>jp.gr.java_conf.kojiisd</groupId>
    <artifactId>spring_boot_sample</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>spring_boot_sample</name>
    <url>http://maven.apache.org</url>

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

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

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

ソースの準備

ソースはこんな感じにしました。

[Application.java]

@ComponentScan
@EnableAutoConfiguration
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

[SampleController.java]

@Controller
public class SampleController {
    @RequestMapping("/home")
    @ResponseBody
    public String home() {
        return "Hello World";
    }

}

ビルド

それではビルドしてみましょう。

mvn package

Jarファイルの作成。

13428085  4 10 23:31 spring_boot_sample-1.0-SNAPSHOT.jar

Jarファイルは約13MB。予想通り、spring-bootの方がJarファイルのサイズが大きいですね。

念のため動作確認

こちらも念のため動作確認です。

$ java -jar spring_boot_sample-1.0-SNAPSHOT.jar

動作することを確認しました。

$ curl http://localhost:8080/home/
Hello World

大丈夫そうですね。

さて、今回はJarファイルサイズの比較ということでしたが、予想通りspring−bootの方が大きかったです。しかし、MSF4JはDIを備えていないとか、OR Mapperどうするとか、ServletAPI使えないとか、SpringBoot + MyBatisをよく使う自分としては、なかなか参入障壁が高そう。。。

とはいえ、パフォーマンスが良いこともあるし、これからに期待。次は何を比較しよう。

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4