In addition to the standard course contents, we might use some extra reference materials below whenever needed:
- Clone the project and follow TODO's (TODO 10-16, 20-26, 30-38)
-
Example of a Spring Cloud Load Balanced Rest Template customized with timeout:
/** * RestTemplate Builder * * Following example sets connect timeout of 500ms, * where if client cannot acquire open connection on a socket, * it will time out. * * Operations that timeout on connect events may be retried without * regard to Idempotence. * * The example also shows how to configure the read timeout to 2 * seconds. * This protects the calling client from long running calls in a * downstream server/producer. * * Retries may only be executed across read timeouts if the down * stream operation is idempotent, * use with care. * * @return RestTemplate */ @LoadBalanced @Bean public RestTemplate restTemplate() { return new RestTemplateBuilder() .setConnectTimeout(Duration.ofMillis(500L)) .setReadTimeout(Duration.ofMillis(2000L)) .build(); }
- Add the following configuration class
import org.hsqldb.util.DatabaseManagerSwing;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import javax.annotation.PostConstruct;
import javax.sql.DataSource;
@Configuration
public class HsqldbConfig {
@Autowired
DataSource dataSource;
@Bean
public JdbcTemplate getJdbcTemplate(){
return new JdbcTemplate(dataSource);
}
//default username : sa, password : ''
@PostConstruct
public void getDbManager(){
DatabaseManagerSwing.main(
new String[] { "--url", "jdbc:hsqldb:mem:testdb", "--user", "sa", "--password", ""});
}
}
- Turn off the "java.awt.headless"
System.setProperty("java.awt.headless", "false");
- Follow the lab instruction
-
Spring Boot TDD-driven testing
- Create a new Spring Boot project and follow lab instruction
- Solution project is also included in the above GitHub location
-
OAuth2 presentations
-
OAuth2 lab
- Clone Maven project and follow TODO's startting from TODO-10
- Presentation - only slides 18 to 27
- Lab : Follow instruction under "How to complete this guide/To skip the basics, do the following:" section
-
Spring Lifecycle changes with Spring 5.+ and Java 11
-
Java 11 Drops JSR 250 Annotations, including
@PostConstruct
&@PreDestroy
. See Java 11 Migration Guide and Spring Framework docs -
If using Java 11, you may explicitly import annotations:
implementation 'javax.annotation:javax.annotation-api:1.3.2'
<dependency> <groupId>javax.annotation</groupId> <artifactId>javax.annotation-api</artifactId> <version>1.3.2</version> </dependency>
-
Or, you may use
@Bean
parameters to specific init and cleanup callbacks, see Spring Lifecycle Callbacks for more examples. -
You may also implement the
InitializingBean
orDisposableBean
on the class you want to provide the lifecycle callbacks, but this ties your class to Spring.
-
-
Create a free PWS account (if you have not done so yet) from https://run.pivotal.io/
-
Download and install
cf
cli from https://docs.cloudfoundry.org/cf-cli/install-go-cli.html- If you are using MacOS, you can use Homebrew
brew tap cloudfoundry/tap brew install cf-cli
-
Log in to the PWS
cf login -a api.run.pivotal.io
-
Creat a fat jar from any of your Spring Boot web application
<core-spring-labfiles/lab> ./gradlew 38-rest-ws-solution:build
-
Deploy the application to PCF
<core-spring-labfiles/lab> cf push my-app -p 38-rest-ws-solution/build/libs/38-rest-ws-solution-5.0.c.RELEASE.jar --random-route
-
Display all apps deployed
<core-spring-labfiles/lab> cf apps
-
Access the application from a browser by copying the url of the app and place it into a browser's url
-
You can also manage your applications from PWS App Manager UI by going to https://console.run.pivotal.io/
-
If you enable Actuator in your Spring Boot application, you can visualize and manage your Actuator endpoints in App Manager. See Using Spring Boot Actuators with Apps Manager for more information.
-
Observe that every request has
Authorization
request header set with [PRIVATE DATA HIDDEN], which represents access token<core-spring-labfiles/lab> cf -v app my-app
-
Go to /.cf and observe that there is a file called
config.json
-
Display the contents of `config.json" and observe that it has access token
cat config.json
-
Copy the access token (starting from the character right
bearer
underAuthorization
field and analyze it via https://jwt.io/- Observe that there are three sections
- Observe that there are scopes under payload section
- Clone boot2-mysql-app and follow TODO steps
- How Fast is Spring - Blog
- How Fast is Spring - Short Deck with Flame graphs
- How Fast is Spring - Spring One 2018
-
If you are running Spring Boot apps accessing Pivotal Cloud Foundry Spring Cloud Services, you will need to consider Springboot, Spring Cloud, and Pivotal Spring Cloud Services version dependencies. See Spring Cloud Services Client Dependencies.