[JAVA] Hello World comparison between Spark Framework and Spring Boot

I created a Hello World project with Spark Framework, which is a lightweight java web framework, and Spring Boot, which provides rich functions necessary for development, and compared what I felt.

Premise

Hello World steps in Spark Framework

--Create a Gradle project with an appropriate name from "File"-> "New Gradle Project" in eclipse --Edit build.gradle.

build.gradle


dependencies {
    compile 'com.sparkjava:spark-core:2.8.0'
    //Library required for Spark log output
    compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.25'
}

--Create a main class.

SparkApplication


package spark.sample;

import static spark.Spark.get;
/*
 * This Java source file was generated by the Gradle 'init' task.
 */
public class SparkApplication {
    public static void main(String[] args) {
    	get("/", (req, res) -> {
    		return "HelloWorld Spark";
    	});
    }
}

--Place log4j config file in src / main / resources

log4j.properties



log4j.rootCategory=INFO, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.target=System.err
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{1}: %m%n

This completes the implementation of Hello World in Spark. Running the main class launches the built-in jetty.

スクリーンショット 2019-01-25 0.17.14.png

--Check with browser スクリーンショット 2019-01-25 0.19.37.png

--Startup time: Approximately 590ms --Response time per request: Approximately 7ms

Hello World steps with Spring Boot

-Create a template with Spring Initializer and download the zip. Screenshot 2019-01-25 0.42.30.png

--Extract the zip downloaded earlier, and import it with "File"-> "import"-> "Exisiting Gradle Project" in eclipse.

--Create a Controller class.

SampleController


package spring.sample.sample;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SampleController {
	
	@GetMapping("/")
	public String index() {
		return "HelloWorld SpringBoot";
	}
}

This completes the implementation of Hello World in Spring. When run with SpringBootApp, the built-in tomcat will start.

スクリーンショット 2019-01-25 0.48.38.png

--Check with browser スクリーンショット 2019-01-25 0.49.57.png

--Startup time: Approximately 6s --Response time per request: Approximately 12ms --Since favicon.ico is acquired by default, it is almost the same as Spark except for that.

Impressions

Compare Spark Framework and Spring Boot

--Advantages compared to Spring Boot ――If there is no complicated processing, development seems to proceed faster than Spring. --Development can be started if you know the lambda notation of java8 --Lightweight with few dependent modules --Disadvantages compared to Spring Boot --Since there is no enforcement by the framework in a good sense such as forcing the MVC pattern, it may not be suitable for large-scale development in the sense that you can write as much as you like. ――Since the functions required for an enterprise web application are not a full set, you need to implement or select the technology yourself.

I heard that the processing speed of an application created with SpringBoot will be slower than that of an application implemented with pure java because objects created on the framework side will be generated, and a lighter web frame. I wondered if there was any work, so I found the Spark framework and tried it.

I'll try to implement a simple business logic and if I notice it, I'll post it again.

Recommended Posts

Hello World comparison between Spark Framework and Spring Boot
Hello World with Spring Boot
Hello World with Spring Boot!
Hello World with Spring Boot
Spring Boot Hello World in Eclipse
Until "Hello World" with Spring Boot
(Intellij) Hello World with Spring Boot
Hello World with Eclipse + Spring Boot + Maven
Compare Hello, world! In Spring Boot with Java, Kotlin and Groovy
[Practice! ] Display Hello World in Spring Boot
(IntelliJ + gradle) Hello World with Spring Boot
Hello world! With Spring Boot (Marven + text editor)
Various correspondence table of Spring Framework and Spring Boot
[Java] Hello World with Java 14 x Spring Boot 2.3 x JUnit 5 ~
Hello World (REST API) with Apache Camel + Spring Boot 2
Hello World (console app) with Apache Camel + Spring Boot 2
Hello, World! With Asakusa Framework!
Create a Hello World web app with Spring framework + Jetty
Java --Jersey Framework vs Spring Boot
Hello world with Kotlin and JavaFX
Hello World with Docker and C
Spring profile function, and Spring Boot application.properties
Hello World with GWT 2.8.2 and Maven
Android OS (7.1.2) build and Hello World
Hello world in Java and Gradle
Spring Boot2 Web application development with Visual Studio Code Hello World creation
HTTPS with Spring Boot and Let's Encrypt
Accuracy comparison between Pivot Gaussian elimination and Gaussian elimination
Basic CRUD comparison between Mybatis and Hibernate
Hello world with Kotlin and Tornado FX
How Spring Security works with Hello World
Add spring boot and gradle to eclipse
Minimal Java environment construction and Hello World
Spring Integration Study memorandum ~ Understanding Spring Integration Sample 1. Hello World ~
About designing Spring Boot and unit test environment
Spring Boot Whitelabel Error Page and JSON Response
Differences between Spring Initializr packaging JAR and WAR
Output request and response log in Spring Boot
Hello World at explosive speed with Spring Initializr! !! !!
Build Java environment and output hello world [Beginner]
Until you install Gradle and output "Hello World"
I tried to link JavaFX and Spring Framework.
[Verification] Comparison of Spring Boot vs Micronaut boot speed