Welcome to presentation on Spring boot which is really great and relatively a new project from Spring.io. Its aim is to simplify creating new spring framework based projects and unify their configurations by applying some conventions. This convention over configuration is already successfully applied in so called modern web based frameworks like Grails, Django, Play framework, Rails etc.
2. • What and Why?
• Key features of Spring boot.
• Prototyping using CLI.
• Working with Spring Boot with gradle.
• Packaging Executable Jars / Fat jars
• Managing profiles
• Binding Properties - Configurations
• Using Spring data libraries
• Presentation layer(A glimpse)
• Miscellaneous
Agenda
3. • Spring-boot provides a quick way to create a Spring
based application from dependency management to
convention over configuration.
• It’s not a replacement for Spring framework but it
presents a small surface area for users to approach
and extract value from the rest of Spring.
• To provide a range of non-functional features that
are common to large classes of projects (e.g.
embedded servers, security, metrics, health checks,
externalized configuration)
• Grails 3.0 will be based on Spring Boot.
3
What and Why ?
4. • Stand-alone Spring applications with negligible efforts.
• No code generation and no requirement for XML Config
• Automatic configuration by creating sensible defaults
• Provides Starter dependencies / Starter POMs.
• Structure your code as you like
• Supports Gradle and Maven
• Provides common non-functional production ready features for a
“Real” application such as
– security
– metrics
– health checks
– externalised configuration
Key Features
5. • Quickest way to get a spring app off the ground
• Allows you to run groovy scripts without much boilerplate code
• Not recommended for production
Install using SDK
$ sdk install springboot
Running groovy scripts
$ spring run app.groovy
$ spring jar test.jar app.groovy
Rapid Prototyping : Spring CLI
7. // import org.springframework.web.bind.annotation.Controller
// other imports ...
// @Grab("org.springframework.boot:spring-boot-starter-web:0.5.0")
// @EnableAutoConfiguration
@Controller
class Example {
@RequestMapping("/")
@ResponseBody
public String hello() {
return "Hello World!";
}
// public static void main(String[] args) {
// SpringApplication.run(Example.class, args);
// }
}
What Just Happened ?
8. One-stop-shop for all the Spring and related technology
A set of convenient dependency descriptors
Contain a lot of the dependencies that you need to get a project up
and running quickly
All starters follow a similar naming pattern;
spring-boot-starter-*
Examples
spring-boot-starter-web(tomcat and spring mvc dependencies)
– spring-boot-starter-actuator
– spring-boot-starter-security
– spring-boot-starter-data-rest
– spring-boot-starter-amqp
– spring-boot-starter-data-jpa
– spring-boot-starter-data-elasticsearch
– spring-boot-starter-data-mongodb
Starter POMs
18. •
• Entity class
•
import javax.persistence.*;
@Entity
public class User{
@Id
private Long id;
private String name;
//Getter and Setter
}
Using Spring data:MySQL
19. •
• Add repository interface
import org.springframework.data.jpa.repository.JpaRepository;
public interface UserRepository extends JpaRepository<User, Long>{
User findByName(String name);
}
• Usage
@Autowired
private UserRepository userRepository;
userRepository.findByName();
userRepository.save();
userRepository.findAll();
For more : http://www.oracle.com/technetwork/middleware/ias/toplink-jpa-annotations-
096251.html
22. Actuator for Production
ID Description Sensitiv
e
autoconfig Displays an auto-configuration report showing all auto- configuration
candidates and the reason why they ‘were’ or ‘were not’ applied.
true
beans Displays a complete list of all the Spring beans in your application. true
configprops Displays a collated list of all @ConfigurationProperties. true
dump Performs a thread dump. true
env Exposes properties from Spring’s ConfigurableEnvironment. true
health Shows application health information (a simple ‘status’ when accessed over
an unauthenticated connection or full message details when authenticated).
false
info Displays arbitrary application info. false
metrics Shows ‘metrics’ information for the current application. true
mappings Displays a collated list of all @RequestMapping paths. true
shutdown Allows the application to be gracefully shutdown (not enabled by default). true
trace Displays trace information (by default the last few HTTP requests). true
23. Miscellaneous
- Enabling Disabling the Banner
- Changing the Banner
(http://www.kammerl.de/ascii/AsciiSignature.php)
- Adding event Listeners
- Logging startup info