diff --git a/Step01.md b/Step01.md index 1e546a0..4ef426d 100644 --- a/Step01.md +++ b/Step01.md @@ -9,15 +9,8 @@ - As far as this step is concerned, we will focus on getting up and running with Spring Boot. We will understand all the magic a little later. - We will copy a lot of code in this step - just to avoid typos -## Useful Snippets and References -First Snippet -``` -``` -Second Snippet -``` -``` - ## Exercises +- If you are comfortable with Spring, try to create a few dependencies and see if are automatically auto-wired! ## Files List ### /pom.xml diff --git a/Step02.md b/Step02.md index 255ddf6..cb509a1 100644 --- a/Step02.md +++ b/Step02.md @@ -1,16 +1,128 @@ ##What You Will Learn during this Step: -- First -- Second -- Third +- Lets add dependencies and see if they are autowired in +- Lets make Spring Boot log the content from Spring Framework in Debug mode ## Useful Snippets and References + First Snippet + ``` + @Component + class SomeBean { + + @Autowired + private SomeDependency someDependency; + + public String calculateSomething() { + // I'm a lazy bugger. Skipping calculation + return someDependency.getSomething(); + } + } + + @Component + class SomeDependency { + + public String getSomething() { + return "something"; + } + + } ``` + Second Snippet ``` +System.out.println(ctx.getBean(SomeBean.class).calculateSomething()); +``` +Third Snippet +``` +/src/main/resources/application.properties +logging.level.org.springframework=DEBUG ``` ## Exercises -## Files List \ No newline at end of file +## Files List +### /pom.xml +``` + + 4.0.0 + com.in28minutes + springboot-for-beginners-example + 0.0.1-SNAPSHOT + Your First Spring Boot Example + war + + + org.springframework.boot + spring-boot-starter-parent + 1.4.0.RELEASE + + + + + org.springframework.boot + spring-boot-starter-web + + + + + 1.8 + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + +``` +### /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; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + ApplicationContext ctx = SpringApplication.run(Application.class, args); + System.out.println(ctx.getBean(SomeBean.class).calculateSomething()); + + } + + @Component + class SomeBean { + + @Autowired + private SomeDependency someDependency; + + public String calculateSomething() { + // I'm a lazy bugger. Skipping calculation + return someDependency.getSomething(); + } + } + + @Component + class SomeDependency { + + public String getSomething() { + return "something"; + } + + } + +} +``` +### /src/main/resources/application.properties +``` +logging.level.org.springframework=DEBUG +``` diff --git a/src/main/.DS_Store b/src/main/.DS_Store new file mode 100644 index 0000000..a71bb84 Binary files /dev/null and b/src/main/.DS_Store differ diff --git a/src/main/java/.DS_Store b/src/main/java/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/src/main/java/.DS_Store differ diff --git a/src/main/java/com/in28minutes/springboot/Application.java b/src/main/java/com/in28minutes/springboot/Application.java index dddb807..070e07b 100644 --- a/src/main/java/com/in28minutes/springboot/Application.java +++ b/src/main/java/com/in28minutes/springboot/Application.java @@ -1,14 +1,38 @@ 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; @SpringBootApplication public class Application { public static void main(String[] args) { ApplicationContext ctx = SpringApplication.run(Application.class, args); + System.out.println(ctx.getBean(SomeBean.class).calculateSomething()); + + } + + @Component + class SomeBean { + + @Autowired + private SomeDependency someDependency; + + public String calculateSomething() { + // I'm a lazy bugger. Skipping calculation + return someDependency.getSomething(); + } + } + + @Component + class SomeDependency { + + public String getSomething() { + return "something"; + } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..b2f5312 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1 @@ +logging.level.org.springframework=DEBUG \ No newline at end of file