SlideShare a Scribd company logo
Rediscovering Spring with
Spring Boot
Gunith Devasurendra
Asso. Tech Lead, CMS
Agenda
● Intro
● Using Maven
● Features and Conventions
● Spring Data with Boot
● Spring MVC with Boot
● Spring Test with Boot
● In Conclusion
Intro
Spring
● What?
● Who?
● Why?
● Why not?
● What is Boot?

Recommended for you

Spring design-juergen-qcon
Spring design-juergen-qconSpring design-juergen-qcon
Spring design-juergen-qcon

This document summarizes new features in Spring 3 and 3.1 for component-based application design. Spring 3 focuses on annotation-based components while also supporting concise XML configurations. Key features include stereotypes, factory methods, expression language support, standardized annotations, validation, formatting, scheduling, and REST support. Spring 3.1 enhances environments with profiles for bean definitions, enables Java-based configuration, adds a "c:" namespace for XML, and introduces declarative caching capabilities.

Elastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara MicroElastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara Micro

This session will explain how to build modern and scalable applications, while efficiently adding business value. With the right tools, technical decisions can be deferred and problems can be solved according to business needs instead. Payara Micro – an open source MicroProfile-compatible runtime – provides these tools in an easy-to-use package, allowing developers to focus on getting the job done. In addition, it can be connected using a standard API to Apache Kafka or Amazon SQS for high performance messaging. In this talk, you’ll learn how to create an architecture around all these tools to get as much flexibility as possible and be ready to deploy your applications into cloud. During a live demonstration, you’ll see how a Java EE application can benefit from dynamic clustering, MicroProfile API, distributed configuration and scalable cache built into the Payara Micro runtime.

javaeecloudpayara-micro
Elastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara MicroElastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara Micro

This document discusses how to build elastic and cloud-ready applications using Payara Micro. It covers several key aspects: 1) Payara Micro provides a scalable runtime by allowing applications to run as a lightweight executable JAR file that can dynamically form clusters of multiple instances for scalability. 2) Features like JCache, CDI events, and JCA connectors allow applications to support requirements for cloud deployments like pluggable persistence, loose coupling, and failure recovery. 3) Microprofile Config allows applications to access configuration from external sources in a standardized way, and Microprofile metrics and health provide monitoring capabilities. 4) Payara Micro integrates these technologies to provide a complete solution for building resilient

javacloudpayara micro
Spring is a beast!
Spring.. Boot?
Spring made Simple
‘Spring Boot makes it easy to create stand-alone,
production-grade Spring based Applications that you can
“just run”’
New recommended way of running Spring programs
Goals
● Faster and more accessible initial setup
● Default Configurations and the ability to Customize
● No code generation and No XML configs
System Requirements
● Java 6+ (8 recommended)
● Spring 4.1.5+
That's it! Simply include the appropriate spring-boot-*.jar
files on your classpath.
---
● But, Recommended to use Build scripts:
○ Maven (3.2+), Gradle (1.12+)
● Also, Out-of-box supported Servlet containers:
○ Tomcat 7+, Jetty 8+, Undertow 1.1
Using Maven

Recommended for you

Elastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara MicroElastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara Micro

First presneted at the W-JAX Conference in Munich, Germany on the 8th of November 2017. This session will explain how to build modern and scalable applications, while efficiently adding business value. With the right tools, technical decisions can be deferred and problems can be solved according to business needs instead. Payara Micro – an open source MicroProfile-compatible runtime – provides these tools in an easy-to-use package, allowing developers to focus on getting the job done. In addition, it can be connected using a standard API to Apache Kafka or Amazon SQS for high performance messaging. In this talk, you’ll learn how to create an architecture around all these tools to get as much flexibility as possible and be ready to deploy your applications into cloud. During a live demonstration, you’ll see how a Java EE application can benefit from dynamic clustering, MicroProfile API, distributed configuration and scalable cache built into the Payara Micro runtime.

java eejavapayara server
Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking Tour

This talk introduces how to build applications using some of the features in Spring 3.1, the new framework from SpringSource, a division of VMWare

3.1springmvc
Modular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSModular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJS

The document discusses creating modular test-driven single page applications (SPAs) using Spring and AngularJS. It provides an overview of AngularJS concepts and how to integrate AngularJS with Spring, including building and deploying AngularJS apps, modularization, and testing. It also covers AngularJS basics like models, views, controllers, directives, and modules.

springangularjsgrunt
Using Maven : Parent POM & Dependency
Inherit from the spring-boot-starter-parent project to
obtain sensible defaults:
Java 6 compiler, UTF-8 code, Sensible resource filtering (ex:
for application.properties), Sensible plugin configs
spring-boot-starter-parent extends from spring-boot-
dependencies which holds a predefined set of dependencies.
● Could easily include dependencies from the parent
● Could override the versions by overriding MVN variables
<properties>
<java.version>1.8</java.version>
</properties>
Using Maven : Starter POMs
Starter POMs are a set of convenient dependency descriptors
that you can include in your application
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> ^-- No need for version as it comes
</dependencies> from Parent POM
Has many more including:
spring-boot-starter-amqp, spring-boot-starter-batch,
spring-boot-starter-data-jpa, spring-boot-starter-data-rest,
spring-boot-starter-mail, spring-boot-starter-mobile,
spring-boot-starter-test, spring-boot-starter-logging,
spring-boot-starter-ws spring-security-oauth2
Build File Generation
https://start.spring.io/
Features and Conventions

Recommended for you

Spring5 New Features
Spring5 New FeaturesSpring5 New Features
Spring5 New Features

Spring 5 includes several major changes such as Java 9 compatibility, support for Java EE 8, and reactive programming support using WebFlux and router functions. It also upgrades dependencies to newer versions including JDK 8+, upgrades testing to support JUnit 5, and deprecates some older technologies. Performance has been enhanced through faster component scanning and other optimizations.

springspring bootspring5
Resthub lyonjug
Resthub lyonjugResthub lyonjug
Resthub lyonjug

This document discusses RESThub, a full stack Java and JavaScript framework. It provides a plugin-based architecture using Spring and Maven. The Java stack includes generic DAO, service, and test classes along with JPA and validation. The JavaScript stack supports routing, classes, controllers, templates, widgets, and repositories to enable building rich client applications with a REST backend. Examples and roadmaps are also mentioned.

html5springresthub
Spring Boot
Spring BootSpring Boot
Spring Boot

Spring Boot is an open source Java-based framework that makes it easy to create stand-alone, production-grade Spring based Applications. It provides features such as embedded HTTP servers, externalized configuration, and metrics. Spring Boot uses auto-configuration and starters to minimize configuration work. The main intention of Spring Boot starters is to combine common dependencies into single dependencies to simplify dependency management. Spring Boot also provides auto-configuration to avoid explicit configuration of components like views and ViewResolvers.

springjavaspring boot
Main Class
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Just starts up deamon. To build CLI apps, use Spring Boot
CLI
SpringApplication can be customized by calling different
setters
Ex: Command line params, add listeners, shutdown hooks
@SpringBootApplication
}
Code Structure
@ComponentScan automatically picks up all Spring components
com
+- example
+- myproject
+- Application.java <- Main application class is in a
| root package above other classes
+- domain for correct @ComponentScan
| +- Customer.java
| +- CustomerRepository.java
|
+- service
| +- CustomerService.java
|
+- web
+- CustomerController.java
Defining Beans in @Configuration
Spring Boot favors Java-based @Configuration over XML
Config, which is more traditional.
@Configuration
public class AdsdaqCoreDatasourceConfiguration {
@Bean(name = “dataSourceMain”)
@ConfigurationProperties(prefix = “datasource.main”)
@Primary
public DataSource dataSourceAdServer() {
return DataSourceBuilder.create().build();
}
}
___
datasource.main.url=jdbc:mysql://localhost:3306/reviewdb
datasource.main.username=root
datasource.main.password=admin
Enabling Auto Configuration
@EnableAutoConfiguration attempts to automatically configure
the application based on the dependencies
At any point you can start to define your own @Configuration
to replace specific parts of the auto-configuration.
Ex: if you add your own DataSource bean, the default
embedded database support will back away.
There are factories defined in
[MVN_repo]orgspringframeworkbootspring-boot-autoconfigure[VER]
[JAR]META-INFspring.factories
These factories only loaded by if satisfied various
conditions (ex: WebMvcAutoConfiguration)

Recommended for you

Spring 3 - Der dritte Frühling
Spring 3 - Der dritte FrühlingSpring 3 - Der dritte Frühling
Spring 3 - Der dritte Frühling

»Spring 3« ist da. Vieles ist geblieben, manches verschwunden, manches neu. Spring 3 verspricht eine verbesserte und dynamischere Konfiguration, einen leistungsfähigen und mächtigen REST-Support und viele kleine Verbesserungen. Parallel zu dem Spring 3-Release wurden auch andere Tools und Projekte aktualisiert, auf die wir ebenfalls einen Blick werfen wollen: * Wichtige Änderungen * Java Configuration * Spring Expression Language * Spring MVC und Rest * Embedded Database * SpringSource Toolsuite * Spring Roo * Grails

UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...

UEMB200: Next Generation of Endpoint Management Architecture and Discovery Services Rex McMillan Lester Memmott

interchangeinterchange17information technology
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction

Rasheed Amir presents on Spring Boot. He discusses how Spring Boot aims to help developers build production-grade Spring applications quickly with minimal configuration. It provides default functionality for tasks like embedding servers and externalizing configuration. Spring Boot favors convention over configuration and aims to get developers started quickly with a single focus. It also exposes auto-configuration for common Spring and related technologies so that applications can take advantage of them without needing to explicitly configure them.

spring bootjavaspring
Spring Beans
Spring provides the following stereotypes for a Spring Bean:
| Annotation | Meaning |
+-------------+-----------------------------------------------------+
| @Component | generic stereotype for any Spring-managed component |
| @Repository | stereotype for persistence layer |
| @Service | stereotype for service layer |
| @Controller | stereotype for presentation layer (spring-mvc) |
Any object with a stereotype as above is identified as a
Spring Bean.
Spring will create them upon container startup and map them
to any @Autowired annotation on an attribute/constructor
Spring Config files
Usually Spring Configuration is stored in file
config/application.properties (or YAML)
Can hard-code values into setters in beans
app.name=MyApp
app.description=${app.name} is a Spring Boot application
This can be overridden by
● runtime variables,
● environment variables,
● profile specific files (application-local.properties),
● based on the location of application.properties,
etc.
Setting Spring Config values to Beans
app.name=MyApp
listener.enable: true
connection.username:
admin
connection.remote-
address: 192.168.1.1
@Value("${app.name}")
private String name;
@Component
@ConditionalOnProperty(prefix = "listener",
name = "enable", matchIfMissing = false)
public class SomeListener { .. }
@Component
@ConfigurationProperties(prefix="connection")
public class ConnectionSettings {
private String username;
@NotNull
private InetAddress remoteAddress;
// ... getters and setters
}
Spring Profiles
Support profiles where the application would act differently
based on the active profile.
Ex: if ‘dev’ profile is passed via env. var.
--spring.profiles.active=dev
If exists,
● Beans with @Profile("dev") will be activated
● File application-dev.properties will be activated
Good for: Dev vs Prod settings, Local Dev vs Default
settings

Recommended for you

Javascript ui for rest services
Javascript ui for rest servicesJavascript ui for rest services
Javascript ui for rest services

Presented at Bucharest Java User Group, http://www.bjug.ro/editii/5.html . Project source code available at: https://github.com/bucharest-jug/dropwizard-todo

require.jsunit testingrest
Dropwizard
DropwizardDropwizard
Dropwizard

Slides accompanying a presentation on Dropwizard I gave at the DevIgnition conference ( www.devignition.com ) on April 29, 2016. The sample code is on GitHub at https://github.com/sleberknight/dropwizard-devignition-2016

restjerseyjetty
SCR Annotations for Fun and Profit
SCR Annotations for Fun and ProfitSCR Annotations for Fun and Profit
SCR Annotations for Fun and Profit

This document discusses using SCR annotations as an alternative to JavaDoc comments for defining OSGi services, references, and components. It provides examples of using annotations to define servlets, references, and configurable components. It also covers using the Apache Felix maven plugin and some best practices like only setting "metatype" to true if the component needs to be configurable.

slingscrlightningtalk
Logging
Spring uses Commons Logging as default.
By default logs to console unless logging.file or logging.
path is set in application.properties.
Set log levels as follows:
logging.level.root=WARN
logging.level.org.springframework.web=DEBUG
If custom logging framework specific configs are to be used
property logging.config
Log format also can be configured.
Building JAR and Running
Spring has plugins for Eclipse, IDEA etc.
Spring Boot has a Maven plugin that can package the project
as an executable jar. Add the plugin to your <plugins>
section if you want to use it:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
Run java -jar target/myproject-0.0.1-SNAPSHOT.jar
Or mvn spring-boot:run
Spring Data with Boot
DB Access with Spring
If you use embeded DB, it only needs MVN dependency.
If you use a production database,
Spring will connection pooling using tomcat-jdbc by
default (via Starters)
spring.datasource.url=jdbc:mysql://localhost/test
spring.datasource.username=dbuser
spring.datasource.password=dbpass
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
There are many more attributes

Recommended for you

Spring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applicationsSpring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applications

Spring Data JPA helps overcome limitations of JDBC API and raw JPA by automatically generating data access code. It reduces boilerplate code through repository interfaces that expose CRUD methods. The programmer defines database access methods in repository interfaces rather than implementing them, avoiding inconsistency. A Spring Data JPA project contains pom.xml, Spring Boot starters, application.properties, and main class annotated with @SpringBootApplication to run the application.

spring
Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1

This document discusses integrating Backbone.js with Spring 3.1. It begins with an overview of new features in Spring 3.1, such as cache abstraction, bean definition profiles, and Java-based configuration. It then provides an introduction to Backbone.js, explaining how it gives structure to web applications using models, collections, views and routers. The document demonstrates how to integrate Backbone.js and Spring 3.1 by using Spring to provide a RESTful JSON API for Backbone models and collections to communicate with, while keeping the UI rendered separately using Backbone views. It provides examples of tasks being managed through GET, POST, PUT and DELETE requests to the Spring API.

CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - HK1 (C...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - HK1 (C...CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - HK1 (C...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - HK1 (C...

https://app.box.com/s/ujmypxg6wegshvv0hmylp5m8hx4dnzrc

Data Access Using JPA and Spring Data - Entity
Using spring-boot-starter-data-jpa.
@Entity classes are ‘scanned’.
import javax.persistence.*;
@Entity
public class City implements Serializable {
@Id
@GeneratedValue
private Long id;
@Column(nullable = false)
private String name;
}
More info about JPA at Hibernate Documentation
Data Access Using JPA and Spring Data - Repository
SQL are autogenerated.
public interface CityRepository extends PagingAndSortingRepository<City, Long>
{
Page<City> findAll(Pageable pageable);
City findByNameAndCountryAllIgnoringCase(String name, String country);
@Query("select c from City c")
Stream<City> findAllByCustomQueryAndStream();
}
● Repository’s subclass CrudRepository generates default
CRUD methods in runtime.
● CrudRepository’s subclass PagingAndSortingRepository
generates paging and sorting methods
Spring Data REST
Is able to easily open a REST interface to the DB using
Spring Data REST by including a spring-boot-starter-data-
rest dependency
Auto serialization
@RepositoryRestResource(collectionResourceRel = "cities", path =
"cities")
interface CityRepository extends Repository<City, Long> {
...
}
Spring MVC with Boot

Recommended for you

Final_SD_Session3_Ferriols, Ador Dionisio, Fajardo.pptx
Final_SD_Session3_Ferriols, Ador Dionisio, Fajardo.pptxFinal_SD_Session3_Ferriols, Ador Dionisio, Fajardo.pptx
Final_SD_Session3_Ferriols, Ador Dionisio, Fajardo.pptx

MATATAG curriculum training

Webinar Innovative assessments for SOcial Emotional Skills
Webinar Innovative assessments for SOcial Emotional SkillsWebinar Innovative assessments for SOcial Emotional Skills
Webinar Innovative assessments for SOcial Emotional Skills

Presentations by Adriano Linzarini and Daniel Catarino da Silva of the OECD Rethinking Assessment of Social and Emotional Skills project from the OECD webinar "Innovations in measuring social and emotional skills and what AI will bring next" on 5 July 2024

oecdeducations&e skills
AI Risk Management: ISO/IEC 42001, the EU AI Act, and ISO/IEC 23894
AI Risk Management: ISO/IEC 42001, the EU AI Act, and ISO/IEC 23894AI Risk Management: ISO/IEC 42001, the EU AI Act, and ISO/IEC 23894
AI Risk Management: ISO/IEC 42001, the EU AI Act, and ISO/IEC 23894

As artificial intelligence continues to evolve, understanding the complexities and regulations regarding AI risk management is more crucial than ever. Amongst others, the webinar covers: • ISO/IEC 42001 standard, which provides guidelines for establishing, implementing, maintaining, and continually improving AI management systems within organizations • insights into the European Union's landmark legislative proposal aimed at regulating AI • framework and methodologies prescribed by ISO/IEC 23894 for identifying, assessing, and mitigating risks associated with AI systems Presenters: Miriama Podskubova - Attorney at Law Miriama is a seasoned lawyer with over a decade of experience. She specializes in commercial law, focusing on transactions, venture capital investments, IT, digital law, and cybersecurity, areas she was drawn to through her legal practice. Alongside preparing contract and project documentation, she ensures the correct interpretation and application of European legal regulations in these fields. Beyond client projects, she frequently speaks at conferences on cybersecurity, online privacy protection, and the increasingly pertinent topic of AI regulation. As a registered advocate of Slovak bar, certified data privacy professional in the European Union (CIPP/e) and a member of the international association ELA, she helps both tech-focused startups and entrepreneurs, as well as international chains, to properly set up their business operations. Callum Wright - Founder and Lead Consultant Founder and Lead Consultant Callum Wright is a seasoned cybersecurity, privacy and AI governance expert. With over a decade of experience, he has dedicated his career to protecting digital assets, ensuring data privacy, and establishing ethical AI governance frameworks. His diverse background includes significant roles in security architecture, AI governance, risk consulting, and privacy management across various industries, thorough testing, and successful implementation, he has consistently delivered exceptional results. Throughout his career, he has taken on multifaceted roles, from leading technical project management teams to owning solutions that drive operational excellence. His conscientious and proactive approach is unwavering, whether he is working independently or collaboratively within a team. His ability to connect with colleagues on a personal level underscores his commitment to fostering a harmonious and productive workplace environment. Date: June 26, 2024 Tags: ISO/IEC 42001, Artificial Intelligence, EU AI Act, ISO/IEC 23894 ------------------------------------------------------------------------------- Find out more about ISO training and certification services Training: ISO/IEC 42001 Artificial Intelligence Management System - EN | PECB Webinars: https://pecb.com/webinars Article: https://pecb.com/article -------------------------------------------------------------------------------

Spring MVC
Spring Boot comes with some auto configuration.
@Controller
@RequestMapping(value="/users")
public class MyRestController {
@RequestMapping(value="/{user}/cust", method=RequestMethod.GET)
ModelAndView getUserCustomers(@PathVariable Long user) {
// ...
}
}
@RestController creates a REST service.
● Expects any static content to be in a directory called
/static (or /public or /resources or /META-INF/resources)
or at spring.resources.staticLocations
● /error mapping by default that handles all errors as a
global error page.
@RequestMapping
@RequestMapping when added to a class would be prefixed to
the @RequestMapping of the method
@RequestMapping method can be called with different
parameters and different return types and it will work
differently
Can also write @RequestMapping to be caught based on,
● RequestMethod (GET, POST..)
● HTTP parameters (ex: params="myParam=myValue")
● HTTP Headers (ex: headers="myHeader=myValue")
Spring MVC : Other features
● Templating: Auto-configuration support for: FreeMarker,
Groovy, Thymeleaf, Velocity, Mustache
○ Templates will be picked up automatically from
src/main/resources/templates
● Other REST Implementations: Support for JAX-RS and Jersey
● Embedded servlet container support: Comes with Starter
Pom. Embeds Tomcat by default. Can go for Jetty, and
Undertow servers as well
○ Can set attributes server.port (default is 8080), server.
address, server.session.timeout values
○ Can deploy as a WAR as well
Spring Test with Boot

Recommended for you

The Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdf
The Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdfThe Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdf
The Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdf

we may assume that God created the cosmos to be his great temple, in which he rested after his creative work. Nevertheless, his special revelatory presence did not fill the entire earth yet, since it was his intention that his human vice-regent, whom he installed in the garden sanctuary, would extend worldwide the boundaries of that sanctuary and of God’s presence. Adam, of course, disobeyed this mandate, so that humanity no longer enjoyed God’s presence in the little localized garden. Consequently, the entire earth became infected with sin and idolatry in a way it had not been previously before the fall, while yet in its still imperfect newly created state. Therefore, the various expressions about God being unable to inhabit earthly structures are best understood, at least in part, by realizing that the old order and sanctuary have been tainted with sin and must be cleansed and recreated before God’s Shekinah presence, formerly limited to heaven and the holy of holies, can dwell universally throughout creation

shekinah sanctuary sabbath
No, it's not a robot: prompt writing for investigative journalism
No, it's not a robot: prompt writing for investigative journalismNo, it's not a robot: prompt writing for investigative journalism
No, it's not a robot: prompt writing for investigative journalism

How to use generative AI tools like ChatGPT and Gemini to generate story ideas for investigations, identify potential sources, and help with coding and writing. A talk from the Centre for Investigative Journalism Summer School, July 2024

journalismgenerative aiideas
How to Store Data on the Odoo 17 Website
How to Store Data on the Odoo 17 WebsiteHow to Store Data on the Odoo 17 Website
How to Store Data on the Odoo 17 Website

Here we are going to discuss how to store data in Odoo 17 Website. It includes defining a model with few fields in it. Add demo data into the model using data directory. Also using a controller, pass the values into the template while rendering it and display the values in the website.

odoo 17data on odoo 17how to store data in odoo
Why need Spring for Tests?
Sometimes we need Spring context
Ex: DB related tests, Web related tests
Can set custom properties for tests using
@TestPropertySource
Has Transaction support, esp for Integration testing for
Auto-rollback
For TestNG, extend AbstractTransactionalTestNGSpringContextTests
In Conclusion
Parting notes
● Can convert your classic Spring app to Spring Boot
● Many guides found in: http://spring.io/guides
● Well documented
___
Pros
● Easy to use. Will soon be the Future
Cons
● Debugging config issues can get tough. Not much help yet
from ‘Googling’
Thank you

Recommended for you

How to Install Theme in the Odoo 17 ERP
How to  Install Theme in the Odoo 17 ERPHow to  Install Theme in the Odoo 17 ERP
How to Install Theme in the Odoo 17 ERP

With Odoo, we can select from a wide selection of attractive themes. Many excellent ones are free to use, while some require payment. Putting an Odoo theme in the Odoo module directory on our server, downloading the theme, and then installing it is a simple process.

odoo 17theme in odoohow to install theme in odoo
The basics of sentences session 9pptx.pptx
The basics of sentences session 9pptx.pptxThe basics of sentences session 9pptx.pptx
The basics of sentences session 9pptx.pptx

Pie

Understanding and Interpreting Teachers’ TPACK for Teaching Multimodalities i...
Understanding and Interpreting Teachers’ TPACK for Teaching Multimodalities i...Understanding and Interpreting Teachers’ TPACK for Teaching Multimodalities i...
Understanding and Interpreting Teachers’ TPACK for Teaching Multimodalities i...

Presented as a plenary session in iTELL 2024 in Salatiga on 4 July 2024. The plenary focuses on understanding and intepreting relevant TPACK competence for teachers to be adept in teaching multimodality in the digital age. It juxtaposes the results of research on multimodality with its contextual implementation in the teaching of English subject in the Indonesian Emancipated Curriculum.

#itell2024tpackdpack

More Related Content

Similar to dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf

Meetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdfMeetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdf
Red Hat
 
Spring boot
Spring bootSpring boot
Spring boot
Gyanendra Yadav
 
Jsp and jstl
Jsp and jstlJsp and jstl
Jsp and jstl
vishal choudhary
 
Spring design-juergen-qcon
Spring design-juergen-qconSpring design-juergen-qcon
Spring design-juergen-qcon
Yiwei Ma
 
Elastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara MicroElastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara Micro
Ondrej Mihályi
 
Elastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara MicroElastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara Micro
Payara
 
Elastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara MicroElastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara Micro
Payara
 
Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking Tour
Joshua Long
 
Modular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSModular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJS
Gunnar Hillert
 
Spring5 New Features
Spring5 New FeaturesSpring5 New Features
Spring5 New Features
Jay Lee
 
Resthub lyonjug
Resthub lyonjugResthub lyonjug
Resthub lyonjug
Sébastien Deleuze
 
Spring Boot
Spring BootSpring Boot
Spring Boot
Jaydeep Kale
 
Spring 3 - Der dritte Frühling
Spring 3 - Der dritte FrühlingSpring 3 - Der dritte Frühling
Spring 3 - Der dritte Frühling
Thorsten Kamann
 
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
Ivanti
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
Rasheed Waraich
 
Javascript ui for rest services
Javascript ui for rest servicesJavascript ui for rest services
Javascript ui for rest services
Ioan Eugen Stan
 
Dropwizard
DropwizardDropwizard
Dropwizard
Scott Leberknight
 
SCR Annotations for Fun and Profit
SCR Annotations for Fun and ProfitSCR Annotations for Fun and Profit
SCR Annotations for Fun and Profit
Mike Pfaff
 
Spring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applicationsSpring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applications
michaelaaron25322
 
Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1
Michał Orman
 

Similar to dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf (20)

Meetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdfMeetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdf
 
Spring boot
Spring bootSpring boot
Spring boot
 
Jsp and jstl
Jsp and jstlJsp and jstl
Jsp and jstl
 
Spring design-juergen-qcon
Spring design-juergen-qconSpring design-juergen-qcon
Spring design-juergen-qcon
 
Elastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara MicroElastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara Micro
 
Elastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara MicroElastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara Micro
 
Elastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara MicroElastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara Micro
 
Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking Tour
 
Modular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSModular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJS
 
Spring5 New Features
Spring5 New FeaturesSpring5 New Features
Spring5 New Features
 
Resthub lyonjug
Resthub lyonjugResthub lyonjug
Resthub lyonjug
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring 3 - Der dritte Frühling
Spring 3 - Der dritte FrühlingSpring 3 - Der dritte Frühling
Spring 3 - Der dritte Frühling
 
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Javascript ui for rest services
Javascript ui for rest servicesJavascript ui for rest services
Javascript ui for rest services
 
Dropwizard
DropwizardDropwizard
Dropwizard
 
SCR Annotations for Fun and Profit
SCR Annotations for Fun and ProfitSCR Annotations for Fun and Profit
SCR Annotations for Fun and Profit
 
Spring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applicationsSpring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applications
 
Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1
 

Recently uploaded

CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - HK1 (C...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - HK1 (C...CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - HK1 (C...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - HK1 (C...
Nguyen Thanh Tu Collection
 
Final_SD_Session3_Ferriols, Ador Dionisio, Fajardo.pptx
Final_SD_Session3_Ferriols, Ador Dionisio, Fajardo.pptxFinal_SD_Session3_Ferriols, Ador Dionisio, Fajardo.pptx
Final_SD_Session3_Ferriols, Ador Dionisio, Fajardo.pptx
shimeathdelrosario1
 
Webinar Innovative assessments for SOcial Emotional Skills
Webinar Innovative assessments for SOcial Emotional SkillsWebinar Innovative assessments for SOcial Emotional Skills
Webinar Innovative assessments for SOcial Emotional Skills
EduSkills OECD
 
AI Risk Management: ISO/IEC 42001, the EU AI Act, and ISO/IEC 23894
AI Risk Management: ISO/IEC 42001, the EU AI Act, and ISO/IEC 23894AI Risk Management: ISO/IEC 42001, the EU AI Act, and ISO/IEC 23894
AI Risk Management: ISO/IEC 42001, the EU AI Act, and ISO/IEC 23894
PECB
 
The Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdf
The Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdfThe Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdf
The Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdf
JackieSparrow3
 
No, it's not a robot: prompt writing for investigative journalism
No, it's not a robot: prompt writing for investigative journalismNo, it's not a robot: prompt writing for investigative journalism
No, it's not a robot: prompt writing for investigative journalism
Paul Bradshaw
 
How to Store Data on the Odoo 17 Website
How to Store Data on the Odoo 17 WebsiteHow to Store Data on the Odoo 17 Website
How to Store Data on the Odoo 17 Website
Celine George
 
How to Install Theme in the Odoo 17 ERP
How to  Install Theme in the Odoo 17 ERPHow to  Install Theme in the Odoo 17 ERP
How to Install Theme in the Odoo 17 ERP
Celine George
 
The basics of sentences session 9pptx.pptx
The basics of sentences session 9pptx.pptxThe basics of sentences session 9pptx.pptx
The basics of sentences session 9pptx.pptx
heathfieldcps1
 
Understanding and Interpreting Teachers’ TPACK for Teaching Multimodalities i...
Understanding and Interpreting Teachers’ TPACK for Teaching Multimodalities i...Understanding and Interpreting Teachers’ TPACK for Teaching Multimodalities i...
Understanding and Interpreting Teachers’ TPACK for Teaching Multimodalities i...
Neny Isharyanti
 
Lecture_Notes_Unit4_Chapter_8_9_10_RDBMS for the students affiliated by alaga...
Lecture_Notes_Unit4_Chapter_8_9_10_RDBMS for the students affiliated by alaga...Lecture_Notes_Unit4_Chapter_8_9_10_RDBMS for the students affiliated by alaga...
Lecture_Notes_Unit4_Chapter_8_9_10_RDBMS for the students affiliated by alaga...
Murugan Solaiyappan
 
matatag curriculum education for Kindergarten
matatag curriculum education for Kindergartenmatatag curriculum education for Kindergarten
matatag curriculum education for Kindergarten
SarahAlie1
 
How to Configure Time Off Types in Odoo 17
How to Configure Time Off Types in Odoo 17How to Configure Time Off Types in Odoo 17
How to Configure Time Off Types in Odoo 17
Celine George
 
Delegation Inheritance in Odoo 17 and Its Use Cases
Delegation Inheritance in Odoo 17 and Its Use CasesDelegation Inheritance in Odoo 17 and Its Use Cases
Delegation Inheritance in Odoo 17 and Its Use Cases
Celine George
 
How to Add Colour Kanban Records in Odoo 17 Notebook
How to Add Colour Kanban Records in Odoo 17 NotebookHow to Add Colour Kanban Records in Odoo 17 Notebook
How to Add Colour Kanban Records in Odoo 17 Notebook
Celine George
 
Unlocking Educational Synergy-DIKSHA & Google Classroom.pptx
Unlocking Educational Synergy-DIKSHA & Google Classroom.pptxUnlocking Educational Synergy-DIKSHA & Google Classroom.pptx
Unlocking Educational Synergy-DIKSHA & Google Classroom.pptx
bipin95
 
Views in Odoo - Advanced Views - Pivot View in Odoo 17
Views in Odoo - Advanced Views - Pivot View in Odoo 17Views in Odoo - Advanced Views - Pivot View in Odoo 17
Views in Odoo - Advanced Views - Pivot View in Odoo 17
Celine George
 
SYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISING
SYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISINGSYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISING
SYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISING
Dr Vijay Vishwakarma
 
NLC English 7 Consolidation Lesson plan for teacher
NLC English 7 Consolidation Lesson plan for teacherNLC English 7 Consolidation Lesson plan for teacher
NLC English 7 Consolidation Lesson plan for teacher
AngelicaLubrica
 
Credit limit improvement system in odoo 17
Credit limit improvement system in odoo 17Credit limit improvement system in odoo 17
Credit limit improvement system in odoo 17
Celine George
 

Recently uploaded (20)

CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - HK1 (C...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - HK1 (C...CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - HK1 (C...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - HK1 (C...
 
Final_SD_Session3_Ferriols, Ador Dionisio, Fajardo.pptx
Final_SD_Session3_Ferriols, Ador Dionisio, Fajardo.pptxFinal_SD_Session3_Ferriols, Ador Dionisio, Fajardo.pptx
Final_SD_Session3_Ferriols, Ador Dionisio, Fajardo.pptx
 
Webinar Innovative assessments for SOcial Emotional Skills
Webinar Innovative assessments for SOcial Emotional SkillsWebinar Innovative assessments for SOcial Emotional Skills
Webinar Innovative assessments for SOcial Emotional Skills
 
AI Risk Management: ISO/IEC 42001, the EU AI Act, and ISO/IEC 23894
AI Risk Management: ISO/IEC 42001, the EU AI Act, and ISO/IEC 23894AI Risk Management: ISO/IEC 42001, the EU AI Act, and ISO/IEC 23894
AI Risk Management: ISO/IEC 42001, the EU AI Act, and ISO/IEC 23894
 
The Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdf
The Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdfThe Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdf
The Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdf
 
No, it's not a robot: prompt writing for investigative journalism
No, it's not a robot: prompt writing for investigative journalismNo, it's not a robot: prompt writing for investigative journalism
No, it's not a robot: prompt writing for investigative journalism
 
How to Store Data on the Odoo 17 Website
How to Store Data on the Odoo 17 WebsiteHow to Store Data on the Odoo 17 Website
How to Store Data on the Odoo 17 Website
 
How to Install Theme in the Odoo 17 ERP
How to  Install Theme in the Odoo 17 ERPHow to  Install Theme in the Odoo 17 ERP
How to Install Theme in the Odoo 17 ERP
 
The basics of sentences session 9pptx.pptx
The basics of sentences session 9pptx.pptxThe basics of sentences session 9pptx.pptx
The basics of sentences session 9pptx.pptx
 
Understanding and Interpreting Teachers’ TPACK for Teaching Multimodalities i...
Understanding and Interpreting Teachers’ TPACK for Teaching Multimodalities i...Understanding and Interpreting Teachers’ TPACK for Teaching Multimodalities i...
Understanding and Interpreting Teachers’ TPACK for Teaching Multimodalities i...
 
Lecture_Notes_Unit4_Chapter_8_9_10_RDBMS for the students affiliated by alaga...
Lecture_Notes_Unit4_Chapter_8_9_10_RDBMS for the students affiliated by alaga...Lecture_Notes_Unit4_Chapter_8_9_10_RDBMS for the students affiliated by alaga...
Lecture_Notes_Unit4_Chapter_8_9_10_RDBMS for the students affiliated by alaga...
 
matatag curriculum education for Kindergarten
matatag curriculum education for Kindergartenmatatag curriculum education for Kindergarten
matatag curriculum education for Kindergarten
 
How to Configure Time Off Types in Odoo 17
How to Configure Time Off Types in Odoo 17How to Configure Time Off Types in Odoo 17
How to Configure Time Off Types in Odoo 17
 
Delegation Inheritance in Odoo 17 and Its Use Cases
Delegation Inheritance in Odoo 17 and Its Use CasesDelegation Inheritance in Odoo 17 and Its Use Cases
Delegation Inheritance in Odoo 17 and Its Use Cases
 
How to Add Colour Kanban Records in Odoo 17 Notebook
How to Add Colour Kanban Records in Odoo 17 NotebookHow to Add Colour Kanban Records in Odoo 17 Notebook
How to Add Colour Kanban Records in Odoo 17 Notebook
 
Unlocking Educational Synergy-DIKSHA & Google Classroom.pptx
Unlocking Educational Synergy-DIKSHA & Google Classroom.pptxUnlocking Educational Synergy-DIKSHA & Google Classroom.pptx
Unlocking Educational Synergy-DIKSHA & Google Classroom.pptx
 
Views in Odoo - Advanced Views - Pivot View in Odoo 17
Views in Odoo - Advanced Views - Pivot View in Odoo 17Views in Odoo - Advanced Views - Pivot View in Odoo 17
Views in Odoo - Advanced Views - Pivot View in Odoo 17
 
SYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISING
SYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISINGSYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISING
SYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISING
 
NLC English 7 Consolidation Lesson plan for teacher
NLC English 7 Consolidation Lesson plan for teacherNLC English 7 Consolidation Lesson plan for teacher
NLC English 7 Consolidation Lesson plan for teacher
 
Credit limit improvement system in odoo 17
Credit limit improvement system in odoo 17Credit limit improvement system in odoo 17
Credit limit improvement system in odoo 17
 

dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf

  • 1. Rediscovering Spring with Spring Boot Gunith Devasurendra Asso. Tech Lead, CMS
  • 2. Agenda ● Intro ● Using Maven ● Features and Conventions ● Spring Data with Boot ● Spring MVC with Boot ● Spring Test with Boot ● In Conclusion
  • 4. Spring ● What? ● Who? ● Why? ● Why not? ● What is Boot?
  • 5. Spring is a beast!
  • 6. Spring.. Boot? Spring made Simple ‘Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can “just run”’ New recommended way of running Spring programs Goals ● Faster and more accessible initial setup ● Default Configurations and the ability to Customize ● No code generation and No XML configs
  • 7. System Requirements ● Java 6+ (8 recommended) ● Spring 4.1.5+ That's it! Simply include the appropriate spring-boot-*.jar files on your classpath. --- ● But, Recommended to use Build scripts: ○ Maven (3.2+), Gradle (1.12+) ● Also, Out-of-box supported Servlet containers: ○ Tomcat 7+, Jetty 8+, Undertow 1.1
  • 9. Using Maven : Parent POM & Dependency Inherit from the spring-boot-starter-parent project to obtain sensible defaults: Java 6 compiler, UTF-8 code, Sensible resource filtering (ex: for application.properties), Sensible plugin configs spring-boot-starter-parent extends from spring-boot- dependencies which holds a predefined set of dependencies. ● Could easily include dependencies from the parent ● Could override the versions by overriding MVN variables <properties> <java.version>1.8</java.version> </properties>
  • 10. Using Maven : Starter POMs Starter POMs are a set of convenient dependency descriptors that you can include in your application <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> ^-- No need for version as it comes </dependencies> from Parent POM Has many more including: spring-boot-starter-amqp, spring-boot-starter-batch, spring-boot-starter-data-jpa, spring-boot-starter-data-rest, spring-boot-starter-mail, spring-boot-starter-mobile, spring-boot-starter-test, spring-boot-starter-logging, spring-boot-starter-ws spring-security-oauth2
  • 13. Main Class @Configuration @EnableAutoConfiguration @ComponentScan public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } Just starts up deamon. To build CLI apps, use Spring Boot CLI SpringApplication can be customized by calling different setters Ex: Command line params, add listeners, shutdown hooks @SpringBootApplication }
  • 14. Code Structure @ComponentScan automatically picks up all Spring components com +- example +- myproject +- Application.java <- Main application class is in a | root package above other classes +- domain for correct @ComponentScan | +- Customer.java | +- CustomerRepository.java | +- service | +- CustomerService.java | +- web +- CustomerController.java
  • 15. Defining Beans in @Configuration Spring Boot favors Java-based @Configuration over XML Config, which is more traditional. @Configuration public class AdsdaqCoreDatasourceConfiguration { @Bean(name = “dataSourceMain”) @ConfigurationProperties(prefix = “datasource.main”) @Primary public DataSource dataSourceAdServer() { return DataSourceBuilder.create().build(); } } ___ datasource.main.url=jdbc:mysql://localhost:3306/reviewdb datasource.main.username=root datasource.main.password=admin
  • 16. Enabling Auto Configuration @EnableAutoConfiguration attempts to automatically configure the application based on the dependencies At any point you can start to define your own @Configuration to replace specific parts of the auto-configuration. Ex: if you add your own DataSource bean, the default embedded database support will back away. There are factories defined in [MVN_repo]orgspringframeworkbootspring-boot-autoconfigure[VER] [JAR]META-INFspring.factories These factories only loaded by if satisfied various conditions (ex: WebMvcAutoConfiguration)
  • 17. Spring Beans Spring provides the following stereotypes for a Spring Bean: | Annotation | Meaning | +-------------+-----------------------------------------------------+ | @Component | generic stereotype for any Spring-managed component | | @Repository | stereotype for persistence layer | | @Service | stereotype for service layer | | @Controller | stereotype for presentation layer (spring-mvc) | Any object with a stereotype as above is identified as a Spring Bean. Spring will create them upon container startup and map them to any @Autowired annotation on an attribute/constructor
  • 18. Spring Config files Usually Spring Configuration is stored in file config/application.properties (or YAML) Can hard-code values into setters in beans app.name=MyApp app.description=${app.name} is a Spring Boot application This can be overridden by ● runtime variables, ● environment variables, ● profile specific files (application-local.properties), ● based on the location of application.properties, etc.
  • 19. Setting Spring Config values to Beans app.name=MyApp listener.enable: true connection.username: admin connection.remote- address: 192.168.1.1 @Value("${app.name}") private String name; @Component @ConditionalOnProperty(prefix = "listener", name = "enable", matchIfMissing = false) public class SomeListener { .. } @Component @ConfigurationProperties(prefix="connection") public class ConnectionSettings { private String username; @NotNull private InetAddress remoteAddress; // ... getters and setters }
  • 20. Spring Profiles Support profiles where the application would act differently based on the active profile. Ex: if ‘dev’ profile is passed via env. var. --spring.profiles.active=dev If exists, ● Beans with @Profile("dev") will be activated ● File application-dev.properties will be activated Good for: Dev vs Prod settings, Local Dev vs Default settings
  • 21. Logging Spring uses Commons Logging as default. By default logs to console unless logging.file or logging. path is set in application.properties. Set log levels as follows: logging.level.root=WARN logging.level.org.springframework.web=DEBUG If custom logging framework specific configs are to be used property logging.config Log format also can be configured.
  • 22. Building JAR and Running Spring has plugins for Eclipse, IDEA etc. Spring Boot has a Maven plugin that can package the project as an executable jar. Add the plugin to your <plugins> section if you want to use it: <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> Run java -jar target/myproject-0.0.1-SNAPSHOT.jar Or mvn spring-boot:run
  • 24. DB Access with Spring If you use embeded DB, it only needs MVN dependency. If you use a production database, Spring will connection pooling using tomcat-jdbc by default (via Starters) spring.datasource.url=jdbc:mysql://localhost/test spring.datasource.username=dbuser spring.datasource.password=dbpass spring.datasource.driver-class-name=com.mysql.jdbc.Driver There are many more attributes
  • 25. Data Access Using JPA and Spring Data - Entity Using spring-boot-starter-data-jpa. @Entity classes are ‘scanned’. import javax.persistence.*; @Entity public class City implements Serializable { @Id @GeneratedValue private Long id; @Column(nullable = false) private String name; } More info about JPA at Hibernate Documentation
  • 26. Data Access Using JPA and Spring Data - Repository SQL are autogenerated. public interface CityRepository extends PagingAndSortingRepository<City, Long> { Page<City> findAll(Pageable pageable); City findByNameAndCountryAllIgnoringCase(String name, String country); @Query("select c from City c") Stream<City> findAllByCustomQueryAndStream(); } ● Repository’s subclass CrudRepository generates default CRUD methods in runtime. ● CrudRepository’s subclass PagingAndSortingRepository generates paging and sorting methods
  • 27. Spring Data REST Is able to easily open a REST interface to the DB using Spring Data REST by including a spring-boot-starter-data- rest dependency Auto serialization @RepositoryRestResource(collectionResourceRel = "cities", path = "cities") interface CityRepository extends Repository<City, Long> { ... }
  • 29. Spring MVC Spring Boot comes with some auto configuration. @Controller @RequestMapping(value="/users") public class MyRestController { @RequestMapping(value="/{user}/cust", method=RequestMethod.GET) ModelAndView getUserCustomers(@PathVariable Long user) { // ... } } @RestController creates a REST service. ● Expects any static content to be in a directory called /static (or /public or /resources or /META-INF/resources) or at spring.resources.staticLocations ● /error mapping by default that handles all errors as a global error page.
  • 30. @RequestMapping @RequestMapping when added to a class would be prefixed to the @RequestMapping of the method @RequestMapping method can be called with different parameters and different return types and it will work differently Can also write @RequestMapping to be caught based on, ● RequestMethod (GET, POST..) ● HTTP parameters (ex: params="myParam=myValue") ● HTTP Headers (ex: headers="myHeader=myValue")
  • 31. Spring MVC : Other features ● Templating: Auto-configuration support for: FreeMarker, Groovy, Thymeleaf, Velocity, Mustache ○ Templates will be picked up automatically from src/main/resources/templates ● Other REST Implementations: Support for JAX-RS and Jersey ● Embedded servlet container support: Comes with Starter Pom. Embeds Tomcat by default. Can go for Jetty, and Undertow servers as well ○ Can set attributes server.port (default is 8080), server. address, server.session.timeout values ○ Can deploy as a WAR as well
  • 33. Why need Spring for Tests? Sometimes we need Spring context Ex: DB related tests, Web related tests Can set custom properties for tests using @TestPropertySource Has Transaction support, esp for Integration testing for Auto-rollback For TestNG, extend AbstractTransactionalTestNGSpringContextTests
  • 35. Parting notes ● Can convert your classic Spring app to Spring Boot ● Many guides found in: http://spring.io/guides ● Well documented ___ Pros ● Easy to use. Will soon be the Future Cons ● Debugging config issues can get tough. Not much help yet from ‘Googling’