Skip to content

aleknow/java8-spring-boot-thymleaf-angular

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A little bit of fresh air for Java Web development

First goal of this project is to show how simple it is to implement an AngularJS application using Spring Boot as a backend, and Bootstrap as a CSS framework. It is freely inspired from the ASP.NET Web API example built by Mathieu and available here: https://github.com/mathieubrun/Samples.AngularBootstrapWebApi.

Second goal is to show what are the framework and tools that we can use today (in 2014) to create light and quick to setup web applications in Java. It leverage on Java 8, Spring Boot, Spring MVC, Thymleaf and AngularJS.

Build and run

Package and run as standalone application:

$ mvn clean package
$ java -jar target/AngularBootstrapSpringBoot-0.1.0.jar

Run inplace and leverage on hot reloading of resources for frontend development:

$ mvn spring-boot:run

Configure

Configure application in application.properties in resources folder (in classpath). This file can be overridden with a copy and specific properties in current dir, config folder in classpath or config folder under current dir. It also supports Spring environment profiles. More info in spring-boot readme.

Nice to have properties

See in src/main/resources/application.properties

TODOs

  • enable csrf (find a good way to include token in angularjs requests)
  • mvc test

Tips

Java 8

List of new features

  • Mostly lambdas and everything around this (interfaces improvements, functions, streams, enhancement of collection and nio apis)
  • New date & time API
  • Nashorn JavaScript engine
  • Guava inspired stuff like Optional (yes I know), StringJoiner, Comparator chain
  • See here for a good overview: http://www.techempower.com/blog/2013/03/26/everything-about-java-8/

Set maven compiler

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
</plugin>

Lambdas of course...

Date & time API

Spring Boot

Starters

  • http://projects.spring.io/spring-boot/docs/spring-boot-starters/README.html
  • Set of dependency descriptors for your projects:
    • spring-boot-starter-actuator
    • spring-boot-starter-amqp
    • spring-boot-starter-aop
    • spring-boot-starter-batch
    • spring-boot-starter-data-jpa
    • spring-boot-starter-data-mongodb
    • spring-boot-starter-data-rest
    • spring-boot-starter-integration
    • spring-boot-starter-jdbc
    • spring-boot-starter-jetty
    • spring-boot-starter-log4j
    • spring-boot-starter-logging
    • spring-boot-starter-mobile
    • spring-boot-starter-ops
    • spring-boot-starter-parent
    • spring-boot-starter-redis
    • spring-boot-starter-security
    • spring-boot-starter-shell-crsh
    • spring-boot-starter-shell-remote
    • spring-boot-starter-test
    • spring-boot-starter-thymeleaf
    • spring-boot-starter-tomcat
    • spring-boot-starter-web
    • spring-boot-starter-websocket

MVC

  • @RestController is same as @Controller and @ResponseBody
  • Data validation enabled automatically if hibernate-validator in the classpath (see in pom)
    • @Valid on controller inputs

Actuators

Security

  • See WebSecurityConfig

Logging

  • By default use logback
  • Possible to import base configuration:

Webjars

  • Client side dependencies exposed as maven artifacts: http://www.webjars.org/
  • Automatically published under /webjars
  • See example for jquery

Thymleaf

  • Java XML / XHTML / HTML5 template engine
  • http://www.thymeleaf.org/
  • Integration with SpringMVC
  • Provide an elegant and well-formed way of creating templates that can be correctly displayed by browsers and therefore work also as static prototypes
  • Great interactive tutorial: http://itutorial.thymeleaf.org/

Script inlining

Tests

Code coverage by jacoco

Fluent api for assertion

Unit and integration tests

  • Configure failsafe plugin for integration tests
    • Name those tests with *IT
  • Configure Jacoco to generate specific reports for both unit and integration tests

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 85.8%
  • Java 8.8%
  • HTML 4.6%
  • CSS 0.8%