SlideShare une entreprise Scribd logo
1  sur  54
Télécharger pour lire hors ligne
Java/Spring과 Node.js의 공존 시즌2
(부제: Java/Spring 전성시대에 Node.js가 살아남는 법)
J2V8을 활용한 자바에 빌붙기
Dongsu Jang <iolothebard at gmail dot com>
발표자료
http://slideshare.net/iolo
제주사는/마이너지향/입코딩전문/독거중년/개발자
이 분
이
바로...
만렙 음유시
그러
나,
현실은...
독거중년
아무도 궁금해 하지 않는…
iolo-the-bard
TOC
• BEGIN
• AS-IS
• Nashorn
• ScriptTemplateView
• Node.js
• TO-BE
• J2V8
• VS
• CODE
• END
BEGIN
JUST FOR FUN
개발자여,
불가능한 꿈을 꾸어라
• Just For Fun
• Open Source
• MSA
• Polyglot
• IE8 없는 세상…
그러나,
리얼리스트가 되라
• 현실은 자바 천국…
• 스프링 전성 시대…
• 봄날은 생각보다 오래 가더라…
• Write Once, Ops Forever!
• IE8만 없어지면 될 줄 알았지?
그래도…
npm에 좋은거 많다던데…
J2V8의 역습
J2V8 STRIKES BACK
Java/Spring과 Node.js의 공존 시즌2
AS-IS
AS GOOD AS IT GETS
Spring Velocity DEPRECATED
에 대처하는 우리의 자세
• Thymeleaf?
• 다시 JSP?
• 그냥 Velocity?!
• 참고: https://jira.spring.io/
browse/SPR-13235
React Isomorphic Rendering
에 대처하는 우리의 자세
• React?
• Isomorphic?
• 먹는거임?
• 대세 or Hype!
빌붙기의 기술
• Rhino
• Nashorn
• Node.js
• J2V8
Rhino
• built-in since Java6
• Oldies but Goodies
• Slooooow but Elegant
• 참고: https://
developer.mozilla.org/en-
US/docs/Mozilla/Projects/
Rhino
Nashorn
• built-in since Java8
• Fast & Easy
• try `jrunscript`
• JSR-223 Scripting API
• 참고: http://
openjdk.java.net/projects/
nashorn/
Hello World
with Nashorn
function greeting(name) {
return "hello," + name + "!";
}
ScriptEngine engine = new
ScriptEngineManager().getEngineByName("nashorn");
engine.eval(new FileReader("hello.js"));
Invocable invocable = (Invocable)engine;
Object result = invocable.invokeFunction(
"greeting", "World");
System.out.println(result);
React Isomorphic Rendering
with Nashorn
tomcatapache
webapp
(war)
MySQL
Nashorn
mod_jk
AJPHTTP
JVM
glue
script
ReactDOMServer.renderToString()
자바 기반 템플릿 엔진
React Isomorphic Rendering
with Nashorn
function renderToString(type, props) {
return ReactDOMServer.renderToString(type, props);
}
<div id="main">${reactHtml}</div>
<script src="bundle.js"></script>
$.getJSON('/apis/v1/comments', function (data) {

ReactDOM.render(<CommentList comments={ data }/>,
document.getElementById('main'));

});
React Isomorphic Rendering
with Nashorn
@RequestMapping("/comment_list")
String getCommentList(Model model) {
ScriptEngine engine = new ScriptEngineManager()
.getEngineByName("nashorn");
engine.eval(new FileReader("polyfill.js"));
engine.eval(new FileReader("react.js"));
engine.eval(new FileReader("react-dom-server.js"));
engine.eval(new FileReader("render.js"));
Invocable invocable = (Invocable)engine;
String reactHtml = (String)invocable.invokeFunction(
"renderToString", "CommentList",
demoService.getComments());
model.addAttribute("reactHtml", reactHtml);
return "comment_list";
}
ScriptTemplateView
• since Spring 4.2
• Easy!!
• JSR-223 Scripting API
• Nashorn, Rhino, JRuby,
Jython, …
• Template Engines
• Hadlebars, Mustache, ejs,
Jade and erb, Jinja2, …
ScriptTemplateView
tomcatapache
webapp
(war)
MySQL
Script
Template
View
mod_jk
AJPHTTP
JVM
glue
script
render(template, model, url)
스크립트 언어 기반 템플릿 엔진
ScriptTemplateView
with ejs/Nashorn
@RequestMapping(“/comment_list”)

public String server(Model model) {

model.addAttribute(“comments”,
demoService.getComments());

return "comment_list";

}
<ul>

<% comments.forEach(function (comment) { %>

<li>

<h5><%= comment.content %></h5>

<p><%= comment.author %></p>

</li>

<% }); %>

</ul>
ScriptTemplateView
with ejs/Nashorn
var _compiledTemplates = {};

function render(template, model, url) {

var compiledTemplate = templates[url];

if(!_compiledTemplates[url]) {

_compiledTemplates[url] = compiledTemplate
= ejs.compile(template);

}

return compiledTemplate(toJsonObject(model));

}

function toJsonObject(javaObj) {

var jsonObj = {};

for (var k in javaObj) {

if(javaObj[k] instanceof Java.type("java.lang.Iterable")) {

jsonObj[k] = Java.from(javaObj[k]);

} else {

jsonObj[k] = javaObj[k];

}

}

return jsonObj;

}
ScriptTemplateView
with ejs/Nashorn
@Configuration

public class EjsConfig {

@Bean

public ScriptTemplateConfigurer scriptTemplateConfigurer() {

ScriptTemplateConfigurer bean = new ScriptTemplateConfigurer();

bean.setEngineName("nashorn");

bean.setScripts(

"/server-scripts/nashorn-polyfill.js",

"/META-INF/resources/webjars/ejs/2.4.1/ejs-v2.4.1/ejs.min.js",

"/server-scripts/nashorn-ejs-render.js"

);

bean.setRenderFunction("render");

bean.setSharedEngine(true);

return bean;

}

@Bean

public ViewResolver scriptTemplateViewResolver() {

ScriptTemplateViewResolver bean = new ScriptTemplateViewResolver();

bean.setPrefix("classpath:/templates/ejs/");

bean.setSuffix(".ejs");

return bean;

}

}
Node.js
• Polyglot, MSA or Hype?
• Fast & Easy
• but Another World
• npm에 좋은거 많다던데…
• 참고: https://nodejs.org
React Isomorphic Rendering
with Node.js
tomcatapache
webapp
(war)
MySQL
express
mod_jk
AJPHTTP
JVM
app.js
ReactDOMServer.renderToString()
자바 기반 템플릿 엔진
HTTP
Node.js
HTTP
React Isomorphic Rendering
with Node.js
var ReactDOMServer = require(‘react-dom/server’);
var CommentList = require(‘comment_list’);
app.get(‘/comment_list’, function (req, res, next) {
db.getCommentList(function (err, data) {
ReactDOMServer.renderToString(<CommentList comments={data}/>);
res.send(reactHtml);
};
});
@RequestMapping("/comment_list")
String getCommentList(Model model) {
String reactHtml = restTemplate.getForObject(
"http://localhost:3000/comment_list", String.class);
model.addAttribute("reactHtml", reactHtml);
return "comment_list";
}
<div id="main">${reactHtml}</div>
<script src="bundle.js"></script>
TO-BE
STAY HUNGRY STAY FOOLISH
J2V8
• Open Source Java bindings
for V8
• Licensed under the EPL
• Faaaaast Fresh!
• Run on Java6
• not only V8 but also NodeJS
• Linux, Windows, Mac OS X,
Android ARM, Android x86
• 참고: https://github.com/
eclipsesource/J2V8
J2V8 - TODO
• Marshalling
• JNI performance bottleneck
• Memory Management & GC
• Exception Handling
• Debugger Integration
• JSR-223 Scripting Engine
• Best Practice & Antipatterns
Rhino vs Nashorn vs V8
출처: https://ariya.io/2014/03/nashorn-the-new-rhino-on-the-block
Hello World
with V8/J2V8
V8 v8 = V8.createV8Runtime();
v8.executeScript(FileUtils.readFileToString("hello.js"));
V8Array args = new V8Array(v8).push("World");
String result = v8.executeStringFunction("greeting", args);
System.out.println(result);
args.release();
v8.release();
function greeting(name) {
return "Hello," + name + "!";
}
Hello World
with NodeJS/J2V8
NodeJS nodeJS = NodeJS.createNodeJS();
V8Object hello = nodeJS.require("./hello");
V8Array args = new
V8Array(hello.getRuntime()).push("World");
String result = hello.executeJSFunction("greeting", args);
while (nodeJS.isRunning()) {

nodeJS.handleMessage();

}
System.out.println(result);
args.release();
hello.release();
nodeJS.release();
function greeting(name) {
return "Hello," + name + "!";
}
Putting it all togethter
with J2V8
tomcatapache
webapp
(war)
MySQL
J2V8
mod_jk
AJPHTTP
JVM
server &
shared
scripts
ReactDOMServer.renderToString()
자바스크립트 기반 템플릿 엔진
JNI
npm
Putting it all togethter
with J2V8
채널 고정!
VS
I WANT TO BELIEVE
소스코드
https://github.com/iolo/spring-
template-bench
ab on my machine
• ab -n 100 -c 4
• MacBook Pro (Retina, 15-
inch, Mid 2014)
• OS X El Capitan 10.11.6
• 2.5 GHz Intel Core i7, 16GB
1600 MHz DDR3, 500GB
Apple SSD
THE TRUTH IS
OUT THERE
0
75
150
225
300
Velocity Freemarker Thymeleaf JSP ScriptTemplateView ejs handlebars J2V8TemplateView ejs
Server Only React Nashorn J2V8 Custom J2V8
THE TRUTH IS
OUT THERE
Server Only
React Custom
Nashorn J2V8 J2V8
Velocity 248.15 24.91 83.98 -
Freemarker 216.40 24.44 82.59 -
Thymeleaf 138.60 25.21 89.73 -
JSP 117.05 24.88 93.10 -
Script
TemplateView
ejs 84.40 30.10 86.39 -
handlebars 26.59 38.56 95.62 -
J2V8
TemplateView
ejs 102.65 25.37 207.70 280.90
CODE
SHOW ME THE CODE
소스코드
https://github.com/iolo/jscon-
springboard-demo 또 게시판!
ㅋㅋㅋ
디렉토리 구조
• src/main/java/
• src/main/react/
• src/main/resources/static
• src/main/resources/templates
• pom.xml
• package.json
• webpack.config.js
• target/classes/static
안봐도
비디오~
J2V8 in Action
• pom.xml - Maven Dependencies for J2V8
• J2V8TemplateView/ViewResolver/… for Spring WebMVC
• ex. ejs, handlebars, mustache, jade, …
• require()ing NPM modules
• ex. require("marked")
• webpack.config.js - client and server at once
• React Isomorphic Rendering - ReactDOMServer.renderToString()
• Async. React-Router Isomorphic Rendering - ReactRouter.match()
Time Over
…
END
HO EYO HE HUM
­ Anonymous
“Do not reinvent the wheel,
but make it perfect!”
­ Anonymous
“Reinvent the wheel,
knowing when and how.”
­ Douglas Crockford
“The good thing about reinventing
the wheel is that you can get a
round one.”
– Linus Torvalds
“Just for Fun ;)”
References
• Spring Framework: http://projects.spring.io/spring-framework/
• Node.js: https://nodejs.org
• React: https://facebook.github.io/react/
• React-Router: https://github.com/reactjs/react-router
• ScriptTemplate: https://docs.spring.io/spring/docs/current/spring-framework-reference/
html/view.html#view-script
• J2V8: https://github.com/eclipsesource/J2V8
• Rhino: https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino
• Nashorn: http://openjdk.java.net/projects/nashorn/
• JSR-223: https://jcp.org/en/jsr/detail?id=223
• Isomorphic templating with Spring Boot, Nashorn and React: https://speakerdeck.com/
sdeleuze/isomorphic-templating-with-spring-boot-nashorn-and-react
• Spring mvc 서버로 Hybrid Rendering 전략 질문: https://slipp.net/questions/370
• Spring Project JIRA
• Support JavaScript Templating: https://jira.spring.io/browse/SPR-12266
• Server-side JavaScript improvements: https://jira.spring.io/browse/SPR-13508
• Remove Velocity support: https://jira.spring.io/browse/SPR-13795
• …
EVAL()의 귀환
RETURN OF THE EVAL()
Java/Spring과 Node.js의 공존 시즌3
Q&A
MAY THE **SOURCE** BE WITH YOU
Thanks
THAT’S ALL FOLKS

Contenu connexe

Tendances

[Play.node] node.js 를 사용한 대규모 글로벌(+중국) 서비스
[Play.node] node.js 를 사용한 대규모 글로벌(+중국) 서비스[Play.node] node.js 를 사용한 대규모 글로벌(+중국) 서비스
[Play.node] node.js 를 사용한 대규모 글로벌(+중국) 서비스Dan Kang (강동한)
 
190119 unreal engine c++ 입문 및 팁
190119 unreal engine c++ 입문 및 팁190119 unreal engine c++ 입문 및 팁
190119 unreal engine c++ 입문 및 팁KWANGIL KIM
 
USENIX ATC 2017: Visualizing Performance with Flame Graphs
USENIX ATC 2017: Visualizing Performance with Flame GraphsUSENIX ATC 2017: Visualizing Performance with Flame Graphs
USENIX ATC 2017: Visualizing Performance with Flame GraphsBrendan Gregg
 
쩌는게임기획서 이렇게 쓴다
쩌는게임기획서 이렇게 쓴다쩌는게임기획서 이렇게 쓴다
쩌는게임기획서 이렇게 쓴다Jinho Jung
 
Windows Registered I/O (RIO) vs IOCP
Windows Registered I/O (RIO) vs IOCPWindows Registered I/O (RIO) vs IOCP
Windows Registered I/O (RIO) vs IOCPSeungmo Koo
 
Screen space reflection
Screen space reflectionScreen space reflection
Screen space reflectionBongseok Cho
 
게임 서버 성능 분석하기
게임 서버 성능 분석하기게임 서버 성능 분석하기
게임 서버 성능 분석하기iFunFactory Inc.
 
Modern C++의 타입 추론과 람다, 컨셉
Modern C++의 타입 추론과 람다, 컨셉Modern C++의 타입 추론과 람다, 컨셉
Modern C++의 타입 추론과 람다, 컨셉HyunJoon Park
 
모바일 게임 보안
모바일 게임 보안모바일 게임 보안
모바일 게임 보안TOAST_NHNent
 
[1216 박민근] 게임회사취업및이직에관한조언
[1216 박민근] 게임회사취업및이직에관한조언[1216 박민근] 게임회사취업및이직에관한조언
[1216 박민근] 게임회사취업및이직에관한조언MinGeun Park
 
Linux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old SecretsLinux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old SecretsBrendan Gregg
 
빌드관리 및 디버깅 (2010년 자료)
빌드관리 및 디버깅 (2010년 자료)빌드관리 및 디버깅 (2010년 자료)
빌드관리 및 디버깅 (2010년 자료)YEONG-CHEON YOU
 
HTML5/JSON 을 이용해 범용 2D 맵에디터 제작하기
HTML5/JSON 을 이용해 범용 2D 맵에디터 제작하기HTML5/JSON 을 이용해 범용 2D 맵에디터 제작하기
HTML5/JSON 을 이용해 범용 2D 맵에디터 제작하기Miyu Park
 
FIFA 온라인 3의 MongoDB 사용기
FIFA 온라인 3의 MongoDB 사용기FIFA 온라인 3의 MongoDB 사용기
FIFA 온라인 3의 MongoDB 사용기Jongwon Kim
 
Linux Profiling at Netflix
Linux Profiling at NetflixLinux Profiling at Netflix
Linux Profiling at NetflixBrendan Gregg
 
Unbound/NSD最新情報(OSC 2013 Tokyo/Spring)
Unbound/NSD最新情報(OSC 2013 Tokyo/Spring)Unbound/NSD最新情報(OSC 2013 Tokyo/Spring)
Unbound/NSD最新情報(OSC 2013 Tokyo/Spring)Takashi Takizawa
 
Broken Linux Performance Tools 2016
Broken Linux Performance Tools 2016Broken Linux Performance Tools 2016
Broken Linux Performance Tools 2016Brendan Gregg
 
게임 프로그래밍 기초 공부법
게임 프로그래밍 기초 공부법게임 프로그래밍 기초 공부법
게임 프로그래밍 기초 공부법Chris Ohk
 
프로그래머에게 사랑받는 게임 기획서 작성법
프로그래머에게 사랑받는 게임 기획서 작성법프로그래머에게 사랑받는 게임 기획서 작성법
프로그래머에게 사랑받는 게임 기획서 작성법Lee Sangkyoon (Kay)
 
Windows system - memory개념잡기
Windows system - memory개념잡기Windows system - memory개념잡기
Windows system - memory개념잡기ChangKyu Song
 

Tendances (20)

[Play.node] node.js 를 사용한 대규모 글로벌(+중국) 서비스
[Play.node] node.js 를 사용한 대규모 글로벌(+중국) 서비스[Play.node] node.js 를 사용한 대규모 글로벌(+중국) 서비스
[Play.node] node.js 를 사용한 대규모 글로벌(+중국) 서비스
 
190119 unreal engine c++ 입문 및 팁
190119 unreal engine c++ 입문 및 팁190119 unreal engine c++ 입문 및 팁
190119 unreal engine c++ 입문 및 팁
 
USENIX ATC 2017: Visualizing Performance with Flame Graphs
USENIX ATC 2017: Visualizing Performance with Flame GraphsUSENIX ATC 2017: Visualizing Performance with Flame Graphs
USENIX ATC 2017: Visualizing Performance with Flame Graphs
 
쩌는게임기획서 이렇게 쓴다
쩌는게임기획서 이렇게 쓴다쩌는게임기획서 이렇게 쓴다
쩌는게임기획서 이렇게 쓴다
 
Windows Registered I/O (RIO) vs IOCP
Windows Registered I/O (RIO) vs IOCPWindows Registered I/O (RIO) vs IOCP
Windows Registered I/O (RIO) vs IOCP
 
Screen space reflection
Screen space reflectionScreen space reflection
Screen space reflection
 
게임 서버 성능 분석하기
게임 서버 성능 분석하기게임 서버 성능 분석하기
게임 서버 성능 분석하기
 
Modern C++의 타입 추론과 람다, 컨셉
Modern C++의 타입 추론과 람다, 컨셉Modern C++의 타입 추론과 람다, 컨셉
Modern C++의 타입 추론과 람다, 컨셉
 
모바일 게임 보안
모바일 게임 보안모바일 게임 보안
모바일 게임 보안
 
[1216 박민근] 게임회사취업및이직에관한조언
[1216 박민근] 게임회사취업및이직에관한조언[1216 박민근] 게임회사취업및이직에관한조언
[1216 박민근] 게임회사취업및이직에관한조언
 
Linux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old SecretsLinux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old Secrets
 
빌드관리 및 디버깅 (2010년 자료)
빌드관리 및 디버깅 (2010년 자료)빌드관리 및 디버깅 (2010년 자료)
빌드관리 및 디버깅 (2010년 자료)
 
HTML5/JSON 을 이용해 범용 2D 맵에디터 제작하기
HTML5/JSON 을 이용해 범용 2D 맵에디터 제작하기HTML5/JSON 을 이용해 범용 2D 맵에디터 제작하기
HTML5/JSON 을 이용해 범용 2D 맵에디터 제작하기
 
FIFA 온라인 3의 MongoDB 사용기
FIFA 온라인 3의 MongoDB 사용기FIFA 온라인 3의 MongoDB 사용기
FIFA 온라인 3의 MongoDB 사용기
 
Linux Profiling at Netflix
Linux Profiling at NetflixLinux Profiling at Netflix
Linux Profiling at Netflix
 
Unbound/NSD最新情報(OSC 2013 Tokyo/Spring)
Unbound/NSD最新情報(OSC 2013 Tokyo/Spring)Unbound/NSD最新情報(OSC 2013 Tokyo/Spring)
Unbound/NSD最新情報(OSC 2013 Tokyo/Spring)
 
Broken Linux Performance Tools 2016
Broken Linux Performance Tools 2016Broken Linux Performance Tools 2016
Broken Linux Performance Tools 2016
 
게임 프로그래밍 기초 공부법
게임 프로그래밍 기초 공부법게임 프로그래밍 기초 공부법
게임 프로그래밍 기초 공부법
 
프로그래머에게 사랑받는 게임 기획서 작성법
프로그래머에게 사랑받는 게임 기획서 작성법프로그래머에게 사랑받는 게임 기획서 작성법
프로그래머에게 사랑받는 게임 기획서 작성법
 
Windows system - memory개념잡기
Windows system - memory개념잡기Windows system - memory개념잡기
Windows system - memory개념잡기
 

Similaire à Java/Spring과 Node.js의 공존 시즌2

I know why your Java is slow
I know why your Java is slowI know why your Java is slow
I know why your Java is slowaragozin
 
Java/Spring과 Node.js의공존
Java/Spring과 Node.js의공존Java/Spring과 Node.js의공존
Java/Spring과 Node.js의공존동수 장
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevMattias Karlsson
 
Server-Side JavaScript with jQuery and AOLserver
Server-Side JavaScript with jQuery and AOLserverServer-Side JavaScript with jQuery and AOLserver
Server-Side JavaScript with jQuery and AOLserverDossy Shiobara
 
Java EE Introduction
Java EE IntroductionJava EE Introduction
Java EE Introductionejlp12
 
Making The Move To Java 17 (JConf 2022)
Making The Move To Java 17 (JConf 2022)Making The Move To Java 17 (JConf 2022)
Making The Move To Java 17 (JConf 2022)Alex Motley
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developergicappa
 
Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaWO Community
 
The Power of the JVM: Applied Polyglot Projects with Java and JavaScript
The Power of the JVM: Applied Polyglot Projects with Java and JavaScriptThe Power of the JVM: Applied Polyglot Projects with Java and JavaScript
The Power of the JVM: Applied Polyglot Projects with Java and JavaScriptHazelcast
 
Ruby on Rails Oracle adaptera izstrāde
Ruby on Rails Oracle adaptera izstrādeRuby on Rails Oracle adaptera izstrāde
Ruby on Rails Oracle adaptera izstrādeRaimonds Simanovskis
 
Self-hosted JS (ffconf 2014)
Self-hosted JS (ffconf 2014)Self-hosted JS (ffconf 2014)
Self-hosted JS (ffconf 2014)Igalia
 
Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScriptelliando dias
 
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...Paul King
 
Javascript why what and how
Javascript why what and howJavascript why what and how
Javascript why what and howsureshpraja1234
 

Similaire à Java/Spring과 Node.js의 공존 시즌2 (20)

Jet presentation
Jet presentationJet presentation
Jet presentation
 
I know why your Java is slow
I know why your Java is slowI know why your Java is slow
I know why your Java is slow
 
Why Java
Why JavaWhy Java
Why Java
 
Java On Speed
Java On SpeedJava On Speed
Java On Speed
 
Just enough app server
Just enough app serverJust enough app server
Just enough app server
 
Java/Spring과 Node.js의공존
Java/Spring과 Node.js의공존Java/Spring과 Node.js의공존
Java/Spring과 Node.js의공존
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
 
Server-Side JavaScript with jQuery and AOLserver
Server-Side JavaScript with jQuery and AOLserverServer-Side JavaScript with jQuery and AOLserver
Server-Side JavaScript with jQuery and AOLserver
 
Java EE Introduction
Java EE IntroductionJava EE Introduction
Java EE Introduction
 
Making The Move To Java 17 (JConf 2022)
Making The Move To Java 17 (JConf 2022)Making The Move To Java 17 (JConf 2022)
Making The Move To Java 17 (JConf 2022)
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
 
Ugo Cei Presentation
Ugo Cei PresentationUgo Cei Presentation
Ugo Cei Presentation
 
Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with Scala
 
The Power of the JVM: Applied Polyglot Projects with Java and JavaScript
The Power of the JVM: Applied Polyglot Projects with Java and JavaScriptThe Power of the JVM: Applied Polyglot Projects with Java and JavaScript
The Power of the JVM: Applied Polyglot Projects with Java and JavaScript
 
Ruby on Rails Oracle adaptera izstrāde
Ruby on Rails Oracle adaptera izstrādeRuby on Rails Oracle adaptera izstrāde
Ruby on Rails Oracle adaptera izstrāde
 
Self-hosted JS (ffconf 2014)
Self-hosted JS (ffconf 2014)Self-hosted JS (ffconf 2014)
Self-hosted JS (ffconf 2014)
 
Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScript
 
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
 
14 mvc
14 mvc14 mvc
14 mvc
 
Javascript why what and how
Javascript why what and howJavascript why what and how
Javascript why what and how
 

Plus de 동수 장

(면접에서 자주 나오는) HTTP : 브라우저에서 서버까지.pdf
(면접에서 자주 나오는) HTTP : 브라우저에서 서버까지.pdf(면접에서 자주 나오는) HTTP : 브라우저에서 서버까지.pdf
(면접에서 자주 나오는) HTTP : 브라우저에서 서버까지.pdf동수 장
 
백세코딩
백세코딩백세코딩
백세코딩동수 장
 
프론트엔드 웹앱 프레임웍 - Bootstrap, Backbone 그리고 AngularJS
프론트엔드 웹앱 프레임웍 - Bootstrap, Backbone 그리고 AngularJS프론트엔드 웹앱 프레임웍 - Bootstrap, Backbone 그리고 AngularJS
프론트엔드 웹앱 프레임웍 - Bootstrap, Backbone 그리고 AngularJS동수 장
 
웹 애플리케이션 프레임웍의 과거,현재 그리고 미래 - 봄날은 간다
웹 애플리케이션 프레임웍의 과거,현재 그리고 미래 - 봄날은 간다웹 애플리케이션 프레임웍의 과거,현재 그리고 미래 - 봄날은 간다
웹 애플리케이션 프레임웍의 과거,현재 그리고 미래 - 봄날은 간다동수 장
 
개발자와 협업하기 위한 API의 이해 - API를 준비하는 금성인을 위한 안내서
개발자와 협업하기 위한 API의 이해 - API를 준비하는 금성인을 위한 안내서개발자와 협업하기 위한 API의 이해 - API를 준비하는 금성인을 위한 안내서
개발자와 협업하기 위한 API의 이해 - API를 준비하는 금성인을 위한 안내서동수 장
 
모바일/클라우드 시대를 준비하는 개발자들을 위한 안내서
모바일/클라우드 시대를 준비하는 개발자들을 위한 안내서모바일/클라우드 시대를 준비하는 개발자들을 위한 안내서
모바일/클라우드 시대를 준비하는 개발자들을 위한 안내서동수 장
 
하이브리드앱 개발 전략과 이슈
하이브리드앱 개발 전략과 이슈하이브리드앱 개발 전략과 이슈
하이브리드앱 개발 전략과 이슈동수 장
 
하이브리드앱 아키텍쳐 및 개발 사례
하이브리드앱 아키텍쳐 및 개발 사례하이브리드앱 아키텍쳐 및 개발 사례
하이브리드앱 아키텍쳐 및 개발 사례동수 장
 
단일 페이지 인터페이스 웹/앱 개발
단일 페이지 인터페이스 웹/앱 개발단일 페이지 인터페이스 웹/앱 개발
단일 페이지 인터페이스 웹/앱 개발동수 장
 
Hybrid Mobile Application Framework
Hybrid Mobile Application FrameworkHybrid Mobile Application Framework
Hybrid Mobile Application Framework동수 장
 
Javascript Common Mistakes
Javascript Common MistakesJavascript Common Mistakes
Javascript Common Mistakes동수 장
 
Gnome Architecture
Gnome ArchitectureGnome Architecture
Gnome Architecture동수 장
 

Plus de 동수 장 (12)

(면접에서 자주 나오는) HTTP : 브라우저에서 서버까지.pdf
(면접에서 자주 나오는) HTTP : 브라우저에서 서버까지.pdf(면접에서 자주 나오는) HTTP : 브라우저에서 서버까지.pdf
(면접에서 자주 나오는) HTTP : 브라우저에서 서버까지.pdf
 
백세코딩
백세코딩백세코딩
백세코딩
 
프론트엔드 웹앱 프레임웍 - Bootstrap, Backbone 그리고 AngularJS
프론트엔드 웹앱 프레임웍 - Bootstrap, Backbone 그리고 AngularJS프론트엔드 웹앱 프레임웍 - Bootstrap, Backbone 그리고 AngularJS
프론트엔드 웹앱 프레임웍 - Bootstrap, Backbone 그리고 AngularJS
 
웹 애플리케이션 프레임웍의 과거,현재 그리고 미래 - 봄날은 간다
웹 애플리케이션 프레임웍의 과거,현재 그리고 미래 - 봄날은 간다웹 애플리케이션 프레임웍의 과거,현재 그리고 미래 - 봄날은 간다
웹 애플리케이션 프레임웍의 과거,현재 그리고 미래 - 봄날은 간다
 
개발자와 협업하기 위한 API의 이해 - API를 준비하는 금성인을 위한 안내서
개발자와 협업하기 위한 API의 이해 - API를 준비하는 금성인을 위한 안내서개발자와 협업하기 위한 API의 이해 - API를 준비하는 금성인을 위한 안내서
개발자와 협업하기 위한 API의 이해 - API를 준비하는 금성인을 위한 안내서
 
모바일/클라우드 시대를 준비하는 개발자들을 위한 안내서
모바일/클라우드 시대를 준비하는 개발자들을 위한 안내서모바일/클라우드 시대를 준비하는 개발자들을 위한 안내서
모바일/클라우드 시대를 준비하는 개발자들을 위한 안내서
 
하이브리드앱 개발 전략과 이슈
하이브리드앱 개발 전략과 이슈하이브리드앱 개발 전략과 이슈
하이브리드앱 개발 전략과 이슈
 
하이브리드앱 아키텍쳐 및 개발 사례
하이브리드앱 아키텍쳐 및 개발 사례하이브리드앱 아키텍쳐 및 개발 사례
하이브리드앱 아키텍쳐 및 개발 사례
 
단일 페이지 인터페이스 웹/앱 개발
단일 페이지 인터페이스 웹/앱 개발단일 페이지 인터페이스 웹/앱 개발
단일 페이지 인터페이스 웹/앱 개발
 
Hybrid Mobile Application Framework
Hybrid Mobile Application FrameworkHybrid Mobile Application Framework
Hybrid Mobile Application Framework
 
Javascript Common Mistakes
Javascript Common MistakesJavascript Common Mistakes
Javascript Common Mistakes
 
Gnome Architecture
Gnome ArchitectureGnome Architecture
Gnome Architecture
 

Dernier

Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 

Dernier (20)

Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 

Java/Spring과 Node.js의 공존 시즌2

  • 1. Java/Spring과 Node.js의 공존 시즌2 (부제: Java/Spring 전성시대에 Node.js가 살아남는 법) J2V8을 활용한 자바에 빌붙기 Dongsu Jang <iolothebard at gmail dot com>
  • 4. TOC • BEGIN • AS-IS • Nashorn • ScriptTemplateView • Node.js • TO-BE • J2V8 • VS • CODE • END
  • 6. 개발자여, 불가능한 꿈을 꾸어라 • Just For Fun • Open Source • MSA • Polyglot • IE8 없는 세상…
  • 7. 그러나, 리얼리스트가 되라 • 현실은 자바 천국… • 스프링 전성 시대… • 봄날은 생각보다 오래 가더라… • Write Once, Ops Forever! • IE8만 없어지면 될 줄 알았지? 그래도… npm에 좋은거 많다던데…
  • 8. J2V8의 역습 J2V8 STRIKES BACK Java/Spring과 Node.js의 공존 시즌2
  • 10. Spring Velocity DEPRECATED 에 대처하는 우리의 자세 • Thymeleaf? • 다시 JSP? • 그냥 Velocity?! • 참고: https://jira.spring.io/ browse/SPR-13235
  • 11. React Isomorphic Rendering 에 대처하는 우리의 자세 • React? • Isomorphic? • 먹는거임? • 대세 or Hype!
  • 12. 빌붙기의 기술 • Rhino • Nashorn • Node.js • J2V8
  • 13. Rhino • built-in since Java6 • Oldies but Goodies • Slooooow but Elegant • 참고: https:// developer.mozilla.org/en- US/docs/Mozilla/Projects/ Rhino
  • 14. Nashorn • built-in since Java8 • Fast & Easy • try `jrunscript` • JSR-223 Scripting API • 참고: http:// openjdk.java.net/projects/ nashorn/
  • 15. Hello World with Nashorn function greeting(name) { return "hello," + name + "!"; } ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn"); engine.eval(new FileReader("hello.js")); Invocable invocable = (Invocable)engine; Object result = invocable.invokeFunction( "greeting", "World"); System.out.println(result);
  • 16. React Isomorphic Rendering with Nashorn tomcatapache webapp (war) MySQL Nashorn mod_jk AJPHTTP JVM glue script ReactDOMServer.renderToString() 자바 기반 템플릿 엔진
  • 17. React Isomorphic Rendering with Nashorn function renderToString(type, props) { return ReactDOMServer.renderToString(type, props); } <div id="main">${reactHtml}</div> <script src="bundle.js"></script> $.getJSON('/apis/v1/comments', function (data) {
 ReactDOM.render(<CommentList comments={ data }/>, document.getElementById('main'));
 });
  • 18. React Isomorphic Rendering with Nashorn @RequestMapping("/comment_list") String getCommentList(Model model) { ScriptEngine engine = new ScriptEngineManager() .getEngineByName("nashorn"); engine.eval(new FileReader("polyfill.js")); engine.eval(new FileReader("react.js")); engine.eval(new FileReader("react-dom-server.js")); engine.eval(new FileReader("render.js")); Invocable invocable = (Invocable)engine; String reactHtml = (String)invocable.invokeFunction( "renderToString", "CommentList", demoService.getComments()); model.addAttribute("reactHtml", reactHtml); return "comment_list"; }
  • 19. ScriptTemplateView • since Spring 4.2 • Easy!! • JSR-223 Scripting API • Nashorn, Rhino, JRuby, Jython, … • Template Engines • Hadlebars, Mustache, ejs, Jade and erb, Jinja2, …
  • 21. ScriptTemplateView with ejs/Nashorn @RequestMapping(“/comment_list”)
 public String server(Model model) {
 model.addAttribute(“comments”, demoService.getComments());
 return "comment_list";
 } <ul>
 <% comments.forEach(function (comment) { %>
 <li>
 <h5><%= comment.content %></h5>
 <p><%= comment.author %></p>
 </li>
 <% }); %>
 </ul>
  • 22. ScriptTemplateView with ejs/Nashorn var _compiledTemplates = {};
 function render(template, model, url) {
 var compiledTemplate = templates[url];
 if(!_compiledTemplates[url]) {
 _compiledTemplates[url] = compiledTemplate = ejs.compile(template);
 }
 return compiledTemplate(toJsonObject(model));
 }
 function toJsonObject(javaObj) {
 var jsonObj = {};
 for (var k in javaObj) {
 if(javaObj[k] instanceof Java.type("java.lang.Iterable")) {
 jsonObj[k] = Java.from(javaObj[k]);
 } else {
 jsonObj[k] = javaObj[k];
 }
 }
 return jsonObj;
 }
  • 23. ScriptTemplateView with ejs/Nashorn @Configuration
 public class EjsConfig {
 @Bean
 public ScriptTemplateConfigurer scriptTemplateConfigurer() {
 ScriptTemplateConfigurer bean = new ScriptTemplateConfigurer();
 bean.setEngineName("nashorn");
 bean.setScripts(
 "/server-scripts/nashorn-polyfill.js",
 "/META-INF/resources/webjars/ejs/2.4.1/ejs-v2.4.1/ejs.min.js",
 "/server-scripts/nashorn-ejs-render.js"
 );
 bean.setRenderFunction("render");
 bean.setSharedEngine(true);
 return bean;
 }
 @Bean
 public ViewResolver scriptTemplateViewResolver() {
 ScriptTemplateViewResolver bean = new ScriptTemplateViewResolver();
 bean.setPrefix("classpath:/templates/ejs/");
 bean.setSuffix(".ejs");
 return bean;
 }
 }
  • 24. Node.js • Polyglot, MSA or Hype? • Fast & Easy • but Another World • npm에 좋은거 많다던데… • 참고: https://nodejs.org
  • 25. React Isomorphic Rendering with Node.js tomcatapache webapp (war) MySQL express mod_jk AJPHTTP JVM app.js ReactDOMServer.renderToString() 자바 기반 템플릿 엔진 HTTP Node.js HTTP
  • 26. React Isomorphic Rendering with Node.js var ReactDOMServer = require(‘react-dom/server’); var CommentList = require(‘comment_list’); app.get(‘/comment_list’, function (req, res, next) { db.getCommentList(function (err, data) { ReactDOMServer.renderToString(<CommentList comments={data}/>); res.send(reactHtml); }; }); @RequestMapping("/comment_list") String getCommentList(Model model) { String reactHtml = restTemplate.getForObject( "http://localhost:3000/comment_list", String.class); model.addAttribute("reactHtml", reactHtml); return "comment_list"; } <div id="main">${reactHtml}</div> <script src="bundle.js"></script>
  • 28. J2V8 • Open Source Java bindings for V8 • Licensed under the EPL • Faaaaast Fresh! • Run on Java6 • not only V8 but also NodeJS • Linux, Windows, Mac OS X, Android ARM, Android x86 • 참고: https://github.com/ eclipsesource/J2V8
  • 29. J2V8 - TODO • Marshalling • JNI performance bottleneck • Memory Management & GC • Exception Handling • Debugger Integration • JSR-223 Scripting Engine • Best Practice & Antipatterns
  • 30. Rhino vs Nashorn vs V8 출처: https://ariya.io/2014/03/nashorn-the-new-rhino-on-the-block
  • 31. Hello World with V8/J2V8 V8 v8 = V8.createV8Runtime(); v8.executeScript(FileUtils.readFileToString("hello.js")); V8Array args = new V8Array(v8).push("World"); String result = v8.executeStringFunction("greeting", args); System.out.println(result); args.release(); v8.release(); function greeting(name) { return "Hello," + name + "!"; }
  • 32. Hello World with NodeJS/J2V8 NodeJS nodeJS = NodeJS.createNodeJS(); V8Object hello = nodeJS.require("./hello"); V8Array args = new V8Array(hello.getRuntime()).push("World"); String result = hello.executeJSFunction("greeting", args); while (nodeJS.isRunning()) {
 nodeJS.handleMessage();
 } System.out.println(result); args.release(); hello.release(); nodeJS.release(); function greeting(name) { return "Hello," + name + "!"; }
  • 33. Putting it all togethter with J2V8 tomcatapache webapp (war) MySQL J2V8 mod_jk AJPHTTP JVM server & shared scripts ReactDOMServer.renderToString() 자바스크립트 기반 템플릿 엔진 JNI npm
  • 34. Putting it all togethter with J2V8 채널 고정!
  • 35. VS I WANT TO BELIEVE
  • 37. ab on my machine • ab -n 100 -c 4 • MacBook Pro (Retina, 15- inch, Mid 2014) • OS X El Capitan 10.11.6 • 2.5 GHz Intel Core i7, 16GB 1600 MHz DDR3, 500GB Apple SSD
  • 38. THE TRUTH IS OUT THERE 0 75 150 225 300 Velocity Freemarker Thymeleaf JSP ScriptTemplateView ejs handlebars J2V8TemplateView ejs Server Only React Nashorn J2V8 Custom J2V8
  • 39. THE TRUTH IS OUT THERE Server Only React Custom Nashorn J2V8 J2V8 Velocity 248.15 24.91 83.98 - Freemarker 216.40 24.44 82.59 - Thymeleaf 138.60 25.21 89.73 - JSP 117.05 24.88 93.10 - Script TemplateView ejs 84.40 30.10 86.39 - handlebars 26.59 38.56 95.62 - J2V8 TemplateView ejs 102.65 25.37 207.70 280.90
  • 42.
  • 43. 디렉토리 구조 • src/main/java/ • src/main/react/ • src/main/resources/static • src/main/resources/templates • pom.xml • package.json • webpack.config.js • target/classes/static 안봐도 비디오~
  • 44. J2V8 in Action • pom.xml - Maven Dependencies for J2V8 • J2V8TemplateView/ViewResolver/… for Spring WebMVC • ex. ejs, handlebars, mustache, jade, … • require()ing NPM modules • ex. require("marked") • webpack.config.js - client and server at once • React Isomorphic Rendering - ReactDOMServer.renderToString() • Async. React-Router Isomorphic Rendering - ReactRouter.match()
  • 47. ­ Anonymous “Do not reinvent the wheel, but make it perfect!”
  • 48. ­ Anonymous “Reinvent the wheel, knowing when and how.”
  • 49. ­ Douglas Crockford “The good thing about reinventing the wheel is that you can get a round one.”
  • 50. – Linus Torvalds “Just for Fun ;)”
  • 51. References • Spring Framework: http://projects.spring.io/spring-framework/ • Node.js: https://nodejs.org • React: https://facebook.github.io/react/ • React-Router: https://github.com/reactjs/react-router • ScriptTemplate: https://docs.spring.io/spring/docs/current/spring-framework-reference/ html/view.html#view-script • J2V8: https://github.com/eclipsesource/J2V8 • Rhino: https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino • Nashorn: http://openjdk.java.net/projects/nashorn/ • JSR-223: https://jcp.org/en/jsr/detail?id=223 • Isomorphic templating with Spring Boot, Nashorn and React: https://speakerdeck.com/ sdeleuze/isomorphic-templating-with-spring-boot-nashorn-and-react • Spring mvc 서버로 Hybrid Rendering 전략 질문: https://slipp.net/questions/370 • Spring Project JIRA • Support JavaScript Templating: https://jira.spring.io/browse/SPR-12266 • Server-side JavaScript improvements: https://jira.spring.io/browse/SPR-13508 • Remove Velocity support: https://jira.spring.io/browse/SPR-13795 • …
  • 52. EVAL()의 귀환 RETURN OF THE EVAL() Java/Spring과 Node.js의 공존 시즌3
  • 53. Q&A MAY THE **SOURCE** BE WITH YOU