Skip to content

Commit

Permalink
Small Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Ranga Rao Karanam authored and Ranga Rao Karanam committed Jan 13, 2017
1 parent c87d7bb commit 93489f2
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 107 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ You will learn about
- Basics of Auto Configuration and Spring Boot Magic
- Spring Boot Starter Projects
- Spring Initializr
- Basic REST Services using Spring Boot Data Web
- Basic REST Services using Spring Boot Starter Web
- REST Service Content Negotiation with JSON and XML
- Embedded servlet containers : Tomcat, Jetty and Undertow
- Writing Unit and Integration tests using Spring Boot Starter Test
Expand Down
19 changes: 4 additions & 15 deletions Step01.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
##What You Will Learn during this Step:
- Set up an Maven Project with Eclipse.
- Intellij Link : https://www.jetbrains.com/help/idea/2016.2/getting-started-with-maven.html#create_maven_project
- Include dependencies needed for Spring Boot.
- spring-boot-starter-web : starter for building applications with Spring MVC. Tomcat is default embedded container.
- spring-boot-maven-plugin : Enable running application in-place and also building a jar/war to run later!
- Copy Two Files pom.xml and Application.java
- Launch Your First Spring Boot Application.

###Typical stuff done at the start of projects
- Framework setup
- Identifying compatible framework versions. for example, Which version of Spring and Hibernate to use?
- Configuring (Integrating) frameworks
- Configuring web.xml, Configuring Dispatcher Servlet
- Configuring data source, session factory
- Logging, Transaction Management, Error Handling
- Configuration Management
- Configuring Servers to deploy applications to
- Monitoring Applications
- You will be introduced to Maven
- Dependency Management

##Cool thing to note!
- Without a lot of configuration, we are up and running with a web application
- Refer https://github.com/in28minutes/SpringMvcStepByStep/blob/master/Step01.md and https://github.com/in28minutes/SpringMvcStepByStep/blob/master/Step11.md to understand the sort of stuff - web.xml, dispatcher servlet configuration, maven dependency management and plugins - that are need to launch a typical web application without Spring Boot!
- Refer https://github.com/in28minutes/SpringMvcStepByStep/blob/master/Step15.md to understand the sort of stuff - web.xml, dispatcher servlet configuration, maven dependency management and plugins - that are need to launch a typical web application without Spring Boot!

##What You Will NOT Learn during this Step:
- Spring Boot does a lot of magic. This magic is called Auto Configuration. We will discuss about different terms related to Spring Boot - Starter Parent, Starter projects, Auto configuration - in depth during our first 10 steps.
Expand Down
147 changes: 71 additions & 76 deletions Step02.md
Original file line number Diff line number Diff line change
@@ -1,69 +1,41 @@
##What You Will Learn during this Step:
- Lets add a RestController with a dependency and see Spring Boot Magic live

##Quick Spring and Spring MVC Primer
##Theory Break : Quick Spring and Spring MVC Primer
- What is dependency?
- @Component
- @Autowired
- @RestController

## Useful Snippets and References

First Snippet

```
@RestController
class SomeBean {
@Autowired
private SomeDependency someDependency;
@RequestMapping("/")
public String index() {
return someDependency.getSomething();
}
}
@Component
class SomeDependency {
public String getSomething() {
return "Hello! Welcome!";
}
}
```

## Files List
### /pom.xml
```
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.in28minutes</groupId>
<artifactId>springboot-for-beginners-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Your First Spring Boot Example</name>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.in28minutes.springboot</groupId>
<artifactId>first-springboot-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
Expand All @@ -73,49 +45,72 @@ First Snippet
</plugin>
</plugins>
</build>
</project>
```
### /src/main/java/com/in28minutes/service/WelcomeService.java
```
package com.in28minutes.service;
import org.springframework.stereotype.Component;
//Spring to manage this bean and create an instance of this
@Component
public class WelcomeService{
public String retrieveWelcomeMessage() {
//Complex Method
return "Good Morning updated! ";
}
}
```
### /src/main/java/com/in28minutes/springboot/Application.java
```
package com.in28minutes.springboot;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan("com.in28minutes")
public class Application {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
}
@RestController
class SomeBean {
@Autowired
private SomeDependency someDependency;
@RequestMapping("/")
public String index() {
return someDependency.getSomething();
}
}
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
for (int i = 0; i < 10; i++)
System.out.println("");
}
@Component
class SomeDependency {
public String getSomething() {
return "Hello! Welcome!";
}
}
```
### /src/main/java/com/in28minutes/springboot/WelcomeController.java
```
package com.in28minutes.springboot;
}
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.in28minutes.service.WelcomeService;
@RestController
public class WelcomeController {
//Auto wiring
@Autowired
private WelcomeService service;
@RequestMapping("/welcome")
public String welcome() {
return service.retrieveWelcomeMessage();
}
}
```
```
43 changes: 28 additions & 15 deletions Step05.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,45 @@
##What You Will Learn during this Step:
- Spring Boot vs Spring
- What Spring Boot is Not!
- Auto component scan
- A programming tip
- Pair Program once in a while!

##Spring Boot vs Spring
###Spring
Spring is just a dependency management framework. Spring focuses on the "plumbing" of enterprise applications so that teams can focus on application-level business logic, without unnecessary ties to specific deployment environments.

### Spring
- Spring is just a dependency injection framework. Spring focuses on the "plumbing" of enterprise applications so that teams can focus on application-level business logic, without unnecessary ties to specific deployment environments.
- First half of the 2000 decade! EJBs
- EJBs were NOT easy to develop.
- Write a lot of xml and plumbing code to get EJBs running
- Impossible to Unit Test
- Alternative - Writing simple JDBC Code involved a lot of plumbing
- Spring framework started with aim of making Java EE development simpler.
- Goals
- Make applications testable. i.e. easier to write unit tests
- Reduce plumbing code of JDBC and JMS
- Simple architecture. Minus EJB.
- Integrates well with other popular frameworks.

###My experience with Spring based Applications
- Developing Spring Based application need configuration of a lot of beans!
- Integration with other frameworks need configuration as well!
- Added to these, applications need other features (logging, transaction management, monitoring, configuration management etc) before they can go live!
- Spring Boot solves these problems

###Spring Boot
- Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can “just run”. Most Spring Boot applications need very little Spring configuration.
- Goals
### Applications with Spring Framework
- Over the next few years, a number of applications were developed with Spring Framework
- Testable but
- Lot of configuration (XML and Java)
- Developing Spring Based application need configuration of a lot of beans!
- Integration with other frameworks need configuration as well!
- In the last few years, focus is moving from monolith applications to microservices. We need to be able to start project quickly. Minimum or Zero start up time
- Framework Setup
- Deployment - Configurability
- Logging, Transaction Management
- Monitoring
- Web Server Configuration

### Spring Boot
- Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can “just run”.
- We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss.
- Example Problem Statements
- You want to add Hibernate to your project. You dont worry about configuring a data source and a session factory. I will do if for you!
- Goals
- Provide quick start for projects with Spring.
- Be opinionated but provide options.
- 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).
- Absolutely no code generation and no requirement for XML configuration.

####What Spring Boot is NOT?
- It’s not an app or a web server
Expand Down

0 comments on commit 93489f2

Please sign in to comment.