#Description: This sample project shows Spring boot 101. Enjoy!
- Pull Maven project from here.
- Navigate to Project root & run following command. It will package and start the application in tomcat server. mvn clean package && java -jar target/*.jar
- Now you can browse to http://localhost:/users/1. You can add context path by editing properties file
All the configuration are bundles in application.properties
All most all the parameters can be configured using application.properties or passing parameter through command line arguments. Example: mvn clean package && java -jar target/.jar –debug mvn clean package && java -jar target/.jar –server.port=9090
Learn basics from http://projects.spring.io/spring-boot/ Look at the Server.java to understand how server is configured to load spring context. Added HSQLDB auto configuration also now. Added Caching for testing purpose. (See cache package to learn)
- create folder src/main/resources/public. Maven will move public folder to classpath while build.
- Add any non-jsp resources in public or sub folders.
- Note: You can create any folder like this and map as resource location in spring
- Note: JSP will not get executed from this folder
- JSP is a whole different story. Include tomcat-embed-jasper in pom dependency
- Now all the JSP in above (resources/public) folder will give you an error or white page.
- To fix this, create folder src/main/resources/META-INF/resources/ then move all jsp in (or sub folders) it. Here I created src/main/resources/META-INF/resources/jsp/helloworld.jsp
- Now maven will move these files to /META-INF/.... This is what Servlet 3.0 expect.
- Run server and access localhost:8080/jsp/helloworld.jsp
Nows lets try to configure using spring MVC 6. See JSPController.java, it uses above given helloworld.jsp 7. You can browse http://localhost:8080/helloworld to see jsp in action 8. Note: You can also store any resources under META_-INF , for example css, js etc.
See packages com.samples.rmi.* for RMI implementation See com.samples.boot.controllers.UserForPerfTestController for endpoint.
Test Result from Macbook Pro 2.7 GHz, 16GB 1600 MHz DDR RAM, OSX Yosemite, JDK 1.8 is given below
REST WINS!!!
4 rounds using 5 request, 1000 Request in total : ab -n1000 -c5 http://localhost:9090/perf/remoting
Time per request: 47.482 [ms] (mean) Time per request: 9.496 [ms] (mean, across all concurrent requests)
Time per request: 39.989 [ms] (mean) Time per request: 7.998 [ms] (mean, across all concurrent requests)
Time per request: 41.329 [ms] (mean) Time per request: 8.266 [ms] (mean, across all concurrent requests)
Time per request: 40.811 [ms] (mean) Time per request: 8.162 [ms] (mean, across all concurrent requests)
4 rounds using 5 request, 1000 Request in total : ab -n1000 -c5 http://localhost:9090/perf/rest
Time per request: 32.753 [ms] (mean) Time per request: 6.551 [ms] (mean, across all concurrent requests)
Time per request: 29.905 [ms] (mean) Time per request: 5.981 [ms] (mean, across all concurrent requests)
Time per request: 28.916 [ms] (mean) Time per request: 5.783 [ms] (mean, across all concurrent requests)
Time per request: 27.966 [ms] (mean) Time per request: 5.593 [ms] (mean, across all concurrent requests)