SpringBoot: Difference between revisions
| Line 68: | Line 68: | ||
* File -> Import -> Maven -> Existing Maven Projects | * File -> Import -> Maven -> Existing Maven Projects | ||
* select <code>C:\Uwes\eclipse\workspace_2020-12\SpringBoot\bookmarks</code> | * select <code>C:\Uwes\eclipse\workspace_2020-12\SpringBoot\bookmarks</code> | ||
====H2 Database Configuration==== | |||
* in <code>C:\Uwes\eclipse\workspace_2020-12\SpringBoot\bookmarks\src\main\resources\application.properties</code> | |||
# to make the h2 database url constant, otherwise it is a random url | |||
spring.datasource.url=jdbc:h2:mem:bookmarksdb | |||
# user and password for H2 console | |||
spring.datasource.username=uwe | |||
spring.datasource.password=uwe | |||
Revision as of 00:49, 7 March 2021
Introduction
- Framework to build microservices
- common non-functional features
- not zero code generation
- not a web or application server
- provides starter projects
- embedded server (incl. in application jar)
- externalized configuration
Concepts
- SpringBoot Autoconfiguration: by scanning the classpath
- Dispatcher Servlet
- SpringBoot Actuator (for monitoring)
Security
adding to pom.xml:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
and update the project automatically sets up form-based authentication with a generated session cookie generated on the server or basic authentication with a header sent along with every request
- user='user
- pwd=see console output of server start
or set it in application.properties
spring.security.user.name=uwe spring.security.user.password=uwe
This has to be entered just once.
Configuration
\test1\src\main\resources\applircation.properties logging.level.org.springframework = debug
Implementation
Main Application
see /test1/src/main/java/com/uweheuer/springboot/test1/Test1Application.java/
@SpringBootApplication
public class Test1Application {
...
public static void main(String[] args) {
SpringApplication.run(Test1Application.class, args);
}
...
Rest Controller
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController @CrossOrigin(origins="http://localhost:4200") // avoid cross origin errors in browser public class HelloWorldController { // @RequestMapping(method=RequestMethod.GET, path="/hello-world") @GetMapping(path="/hello-world")
Resources
Examples
Udemy Course
Bookmarks
- start eclipse
- File -> Import -> Maven -> Existing Maven Projects
- select
C:\Uwes\eclipse\workspace_2020-12\SpringBoot\bookmarks
H2 Database Configuration
- in
C:\Uwes\eclipse\workspace_2020-12\SpringBoot\bookmarks\src\main\resources\application.properties
# to make the h2 database url constant, otherwise it is a random url spring.datasource.url=jdbc:h2:mem:bookmarksdb # user and password for H2 console spring.datasource.username=uwe spring.datasource.password=uwe