spring-boot

Topics related to spring-boot:

Getting started with spring-boot

This section provides an overview of what spring-boot is, and why a developer might want to use it.

It should also mention any large subjects within spring-boot, and link out to the related topics. Since the Documentation for spring-boot is new, you may need to create initial versions of those related topics.

REST Services

Testing in Spring Boot

Spring boot + JPA + mongoDB

Deploying Sample application using Spring-boot on Amazon Elastic Beanstalk

Spring boot + Spring Data JPA

Annotations

@Repository: Indicates that an annotated class is a "Repository", a mechanism for encapsulating storage, retrieval, and search behavior which emulates a collection of objects. Teams implementing traditional J2EE patterns such as "Data Access Object" may also apply this stereotype to DAO classes, though care should be taken to understand the distinction between Data Access Object and DDD-style repositories before doing so. This annotation is a general-purpose stereotype and individual teams may narrow their semantics and use as appropriate.

@RestController: A convenience annotation that is itself annotated with @Controller and @ResponseBody.Types that carry this annotation are treated as controllers where @RequestMapping methods assume @ResponseBody semantics by default.

@Service: Indicates that an annotated class is a "Service" (e.g. a business service facade). This annotation serves as a specialization of @Component, allowing for implementation classes to be autodetected through classpath scanning.

@SpringBootApplication: Many Spring Boot developers always have their main class annotated with @Configuration, @EnableAutoConfiguration and @ComponentScan. Since these annotations are so frequently used together (especially if you follow the best practices above), Spring Boot provides a convenient @SpringBootApplication alternative.

@Entity: Specifies that the class is an entity. This annotation is applied to the entity class.

Official Documentation

Pivotal Software has provided a pretty extensive documentation on Spring Framework, and it can be found at

Fully-Responsive Spring Boot Web Application with JHipster

Create and Use of multiple application.properties files

Caching with Redis Using Spring Boot for MongoDB

Spring Boot + JPA + REST

This example uses Spring Boot, Spring Data JPA and Spring Data REST to expose a simple JPA-managed domain object via REST. The example responds with the HAL JSON format and exposes a url accessible on /person. The maven configuration includes a H2 in-memory database to support a quick standup.

Spring-Boot Microservice with JPA

Spring Boot- Hibernate-REST Integration

ThreadPoolTaskExecutor: configuration and usage

Connecting a spring-boot application to MySQL

As a pre-requisite, make sure that MySQL is already running on port 3306 and has your database created.

Installing the Spring Boot CLI

Once installed, the Spring Boot CLI can be run using the spring command:

To get command-line help:

$ spring help

To create and run your first Spring Boot Project:

$ spring init my-app
$ cd my-app
$ spring run my-app

Open your browser to localhost:8080:

$ open http://localhost:8080

You'll get the whitelabel error page because you haven't yet added any resources to your application, but you're all ready to go with just the following files:

my-app/
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src/
    ├── main/
    │   ├── java/
    │   │   └── com/
    │   │       └── example/
    │   │           └── DemoApplication.java
    │   └── resources/
    │       └── application.properties
    └── test/
        └── java/
            └── com/
                └── example/
                    └── DemoApplicationTests.java
  • mvnw and mvnw.cmd - Maven wrapper scripts that will download and install Maven (if necessary) on the first use.
  • pom.xml - The Maven project definition
  • DemoApplication.java - the main class that launches your Spring Boot application.
  • application.properties - A file for externalized configuration properties. (Can also be given a .yml extension.)
  • DemoApplicationTests.java - A unit test that validates initialization of the Spring Boot application context.

Spring boot + Hibernate + Web UI (Thymeleaf)

Package scanning

Spring-Boot + JDBC

In order to get started, in your sts eclipse go to new --> Spring Starter Project --> fill in your Maven coordinates --> and add the next dependencies:

Under SQL tab --> add JDBC + add MySql (if MySql is your choice).

For Mysql you'll also need to add the MySql Java Connector.

In you Spring Boot application.properties file (you Spring Boot configuration file) you'll need to configure your Data Source credentials to MySql DB:

  1. spring.datasource.url
  2. spring.datasource.username
  3. spring.datasource.password
  4. spring.datasource.driver-class-name

for example:

spring.datasource.url=jdbc:mysql://localhost/test
spring.datasource.username=dbuser
spring.datasource.password=dbpass
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

Under the resources folder add the next two files:

  1. schema.sql --> every time you run your application Spring Boot will run this file, inside it you suppose to write your DB schema, define tables and their relationships.

  2. data.sql --> every time you run your application Spring Boot will run this file, inside it, you suppose to write data that will be inserted into your table as an initial initialization.

Spring Boot will provide you JdbcTemplate bean automatically so you can instantly can you use it like this:

@Autowired
private JdbcTemplate template;

without any other configurations.

Controllers

Spring Boot + Spring Data Elasticsearch