forked from Apress/pro-spring-5
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
00 started working on chapter 3 and polished the project Gradle confi…
…guration. I pushed this commit to GitHub just to give you a taste of how the project will look when the book will be released. ;)
- Loading branch information
0 parents
commit d414191
Showing
1,340 changed files
with
103,945 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.idea | ||
.gradle | ||
*.iml | ||
out | ||
build | ||
gradle | ||
gradlew* | ||
*.class | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.ear | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
|
||
gradlew | ||
gradlew.bat |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Freeware License, some rights reserved | ||
|
||
Copyright (c) 2017 Iuliana Cosmina, Clarence Ho, Rob Harrop, and Chris Schaefer | ||
|
||
Permission is hereby granted, free of charge, to anyone obtaining a copy | ||
of this software and associated documentation files (the "Software"), | ||
to work with the Software within the limits of freeware distribution and fair use. | ||
This includes the rights to use, copy, and modify the Software for personal use. | ||
Users are also allowed and encouraged to submit corrections and modifications | ||
to the Software for the benefit of other users. | ||
|
||
It is not allowed to reuse, modify, or redistribute the Software for | ||
commercial use in any way, or for a user�s educational materials such as books | ||
or blog articles without prior permission from the copyright holder. | ||
|
||
The above copyright notice and this permission notice need to be included | ||
in all copies or substantial portions of the software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
= Apress Source Code | ||
|
||
TODO - change book ISBN | ||
This repository accompanies [*Pro Spring*](http://www.apress.com/9781430261513) by Iuliana Cosmina, Clarence Ho, Rob Harrop, and Chris Schaefer (Apress, 2017). | ||
|
||
TODO change cover image | ||
![Cover image](9781430261513.jpg) | ||
|
||
Download the files as a zip using the green button, or clone the repository to your machine using Git. | ||
|
||
== Releases | ||
Release v1.0 corresponds to the code in the published book, without corrections or updates. | ||
|
||
== Contributions | ||
See the file Contributing.adoc for more information on how you can contribute to this repository. | ||
|
||
== UNDER CONSTRUCTION | ||
|
||
Version 5 of this book is being written so sources here will be changed to use Spring 5.x and Spring Boot 2.x | ||
|
||
|
||
== Building and Deploying | ||
This is a Gradle multi-module project. The *-practice projects, have tests and pieces left unimplemented so building the full project using: | ||
---- | ||
gradle build | ||
---- | ||
will fail. | ||
|
||
In order to build the full project and skipping tests, build from the root (`book-code`) directory: | ||
---- | ||
gradle build -x test | ||
---- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
ext { | ||
springVersion = '5.0.0.M4' | ||
slf4jVersion = '1.7.22' | ||
logbackVersion = '1.1.9' | ||
junitVersion = '4.12' | ||
|
||
spring = [ | ||
context: "org.springframework:spring-context:$springVersion" | ||
] | ||
|
||
testing = [ | ||
junit: "junit:junit:$junitVersion" | ||
] | ||
|
||
misc = [ | ||
slf4jJcl: "org.slf4j:jcl-over-slf4j:$slf4jVersion", | ||
logback : "ch.qos.logback:logback-classic:$logbackVersion" | ||
] | ||
} | ||
|
||
subprojects { | ||
version '5.0-SNAPSHOT' | ||
|
||
repositories { | ||
mavenCentral() | ||
maven { url "http://repo.spring.io/release" } | ||
maven { url "http://repo.spring.io/snapshot" } | ||
maven { url "http://repo.spring.io/milestone" } | ||
} | ||
} | ||
|
||
tasks.withType(JavaCompile) { | ||
options.encoding = "UTF-8" | ||
} | ||
|
||
task wrapper(type: Wrapper) { | ||
gradleVersion = '3.3' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
subprojects { | ||
group 'com.apress.prospring5.ch02' | ||
apply plugin: 'java' | ||
|
||
//Unfortunately, the runtime discovery algorithm in commons-logging, while convenient for the end-user, is problematic | ||
// So the Spring team recommends excluding it and replacing it with SL4j | ||
// https://docs.spring.io/spring/docs/5.0.0.M4/spring-framework-reference/htmlsingle/#overview-not-using-commons-logging | ||
configurations { | ||
all*.exclude group: "commons-logging", module: "commons-logging" | ||
} | ||
|
||
/*Task that copies all the dependencies under build/libs */ | ||
task copyDependencies(type: Copy) { | ||
from configurations.compile | ||
into 'build/libs' | ||
} | ||
|
||
dependencies { | ||
compile spring.context, misc.slf4jJcl, misc.logback | ||
testCompile testing.junit | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
jar { | ||
manifest { | ||
attributes( | ||
'Main-Class': 'com.apress.prospring5.ch2.HelloWorldSpringDI', | ||
"Class-Path": configurations.compile.collect { it.getName() }.join(' ')) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
chapter02/hello-world/src/main/java/com/apress/prospring5/ch2/HelloWorld.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.apress.prospring5.ch2; | ||
|
||
public class HelloWorld { | ||
|
||
public static void main(String... args) { | ||
System.out.println("Hello World!"); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
chapter02/hello-world/src/main/java/com/apress/prospring5/ch2/HelloWorldSpringDI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.apress.prospring5.ch2; | ||
|
||
import com.apress.prospring5.ch2.decoupled.MessageRenderer; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.support.ClassPathXmlApplicationContext; | ||
|
||
public class HelloWorldSpringDI { | ||
public static void main(String... args) { | ||
ApplicationContext ctx = new ClassPathXmlApplicationContext | ||
("spring/app-context.xml"); | ||
|
||
MessageRenderer mr = ctx.getBean("renderer", MessageRenderer.class); | ||
mr.render(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
chapter02/hello-world/src/main/java/com/apress/prospring5/ch2/HelloWorldWithCommandLine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.apress.prospring5.ch2; | ||
|
||
public class HelloWorldWithCommandLine { | ||
|
||
public static void main(String... args) { | ||
if (args.length > 0) { | ||
System.out.println(args[0]); | ||
} else { | ||
System.out.println("Hello World!"); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ello-world/src/main/java/com/apress/prospring5/ch2/annotated/HelloWorldConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.apress.prospring5.ch2.annotated; | ||
|
||
import com.apress.prospring5.ch2.decoupled.HelloWorldMessageProvider; | ||
import com.apress.prospring5.ch2.decoupled.MessageProvider; | ||
import com.apress.prospring5.ch2.decoupled.MessageRenderer; | ||
import com.apress.prospring5.ch2.decoupled.StandardOutMessageRenderer; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* Created by iuliana.cosmina on 1/28/17. | ||
*/ | ||
@Configuration | ||
public class HelloWorldConfiguration { | ||
|
||
@Bean | ||
public MessageProvider provider() { | ||
return new HelloWorldMessageProvider(); | ||
} | ||
|
||
@Bean | ||
public MessageRenderer renderer(){ | ||
MessageRenderer renderer = new StandardOutMessageRenderer(); | ||
renderer.setMessageProvider(provider()); | ||
return renderer; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...lo-world/src/main/java/com/apress/prospring5/ch2/annotated/HelloWorldSpringAnnotated.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.apress.prospring5.ch2.annotated; | ||
|
||
import com.apress.prospring5.ch2.decoupled.MessageRenderer; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
|
||
/** | ||
* Created by iuliana.cosmina on 1/28/17. | ||
*/ | ||
public class HelloWorldSpringAnnotated { | ||
|
||
public static void main(String... args) { | ||
ApplicationContext ctx = new AnnotationConfigApplicationContext | ||
(HelloWorldConfiguration.class); | ||
MessageRenderer mr = ctx.getBean("renderer", MessageRenderer.class); | ||
mr.render(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...02/hello-world/src/main/java/com/apress/prospring5/ch2/decoupled/HelloWorldDecoupled.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.apress.prospring5.ch2.decoupled; | ||
|
||
public class HelloWorldDecoupled { | ||
public static void main(String... args) { | ||
MessageRenderer mr = new StandardOutMessageRenderer(); | ||
MessageProvider mp = new HelloWorldMessageProvider(); | ||
mr.setMessageProvider(mp); | ||
mr.render(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...rld/src/main/java/com/apress/prospring5/ch2/decoupled/HelloWorldDecoupledWithFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.apress.prospring5.ch2.decoupled; | ||
|
||
public class HelloWorldDecoupledWithFactory { | ||
|
||
public static void main(String... args) { | ||
MessageRenderer mr = MessageSupportFactory.getInstance().getMessageRenderer(); | ||
MessageProvider mp = MessageSupportFactory.getInstance().getMessageProvider(); | ||
mr.setMessageProvider(mp); | ||
mr.render(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...lo-world/src/main/java/com/apress/prospring5/ch2/decoupled/HelloWorldMessageProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.apress.prospring5.ch2.decoupled; | ||
|
||
public class HelloWorldMessageProvider implements MessageProvider { | ||
@Override | ||
public String getMessage() { | ||
return "Hello World!"; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
chapter02/hello-world/src/main/java/com/apress/prospring5/ch2/decoupled/MessageProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.apress.prospring5.ch2.decoupled; | ||
|
||
public interface MessageProvider { | ||
String getMessage(); | ||
} |
7 changes: 7 additions & 0 deletions
7
chapter02/hello-world/src/main/java/com/apress/prospring5/ch2/decoupled/MessageRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.apress.prospring5.ch2.decoupled; | ||
|
||
public interface MessageRenderer { | ||
void render(); | ||
void setMessageProvider(MessageProvider provider); | ||
MessageProvider getMessageProvider(); | ||
} |
40 changes: 40 additions & 0 deletions
40
.../hello-world/src/main/java/com/apress/prospring5/ch2/decoupled/MessageSupportFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.apress.prospring5.ch2.decoupled; | ||
|
||
import java.util.Properties; | ||
|
||
public class MessageSupportFactory { | ||
|
||
private static MessageSupportFactory instance; | ||
private Properties props; | ||
private MessageRenderer renderer; | ||
private MessageProvider provider; | ||
|
||
private MessageSupportFactory() { | ||
props = new Properties(); | ||
try { | ||
props.load(this.getClass().getResourceAsStream("/msf.properties")); | ||
String rendererClass = props.getProperty("renderer.class"); | ||
String providerClass = props.getProperty("provider.class"); | ||
renderer = (MessageRenderer) Class.forName(rendererClass).newInstance(); | ||
provider = (MessageProvider) Class.forName(providerClass).newInstance(); | ||
} catch (Exception ex) { | ||
ex.printStackTrace(); | ||
} | ||
} | ||
|
||
static { | ||
instance = new MessageSupportFactory(); | ||
} | ||
|
||
public static MessageSupportFactory getInstance() { | ||
return instance; | ||
} | ||
|
||
public MessageRenderer getMessageRenderer() { | ||
return renderer; | ||
} | ||
|
||
public MessageProvider getMessageProvider() { | ||
return provider; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...o-world/src/main/java/com/apress/prospring5/ch2/decoupled/StandardOutMessageRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.apress.prospring5.ch2.decoupled; | ||
|
||
public class StandardOutMessageRenderer implements MessageRenderer { | ||
|
||
private MessageProvider messageProvider; | ||
|
||
@Override | ||
public void render() { | ||
if (messageProvider == null) { | ||
throw new RuntimeException( | ||
"You must set the property messageProvider of class:" | ||
+ StandardOutMessageRenderer.class.getName()); | ||
} | ||
System.out.println(messageProvider.getMessage()); | ||
} | ||
|
||
@Override | ||
public void setMessageProvider(MessageProvider provider) { | ||
this.messageProvider = provider; | ||
} | ||
|
||
@Override | ||
public MessageProvider getMessageProvider() { | ||
return this.messageProvider; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
renderer.class=com.apress.prospring5.ch2.decoupled.StandardOutMessageRenderer | ||
provider.class=com.apress.prospring5.ch2.decoupled.HelloWorldMessageProvider |
12 changes: 12 additions & 0 deletions
12
chapter02/hello-world/src/main/resources/spring/app-context.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:p="http://www.springframework.org/schema/p" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans | ||
http://www.springframework.org/schema/beans/spring-beans.xsd"> | ||
|
||
<bean id="provider" class="com.apress.prospring5.ch2.decoupled.HelloWorldMessageProvider"/> | ||
|
||
<bean id="renderer" class="com.apress.prospring5.ch2.decoupled.StandardOutMessageRenderer" | ||
p:messageProvider-ref="provider"/> | ||
</beans> |
23 changes: 23 additions & 0 deletions
23
...02/hello-world/src/test/java/com/apress/prospring5/ch2/TestHelloWorldSpringAnnotated.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.apress.prospring5.ch2; | ||
|
||
import com.apress.prospring5.ch2.annotated.HelloWorldConfiguration; | ||
import com.apress.prospring5.ch2.decoupled.MessageRenderer; | ||
import org.junit.Test; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
|
||
/** | ||
* Created by iuliana.cosmina on 1/28/17. | ||
*/ | ||
public class TestHelloWorldSpringAnnotated { | ||
|
||
@Test | ||
public void testHello() { | ||
ApplicationContext ctx = new AnnotationConfigApplicationContext | ||
(HelloWorldConfiguration.class); | ||
MessageRenderer mr = ctx.getBean("renderer", MessageRenderer.class); | ||
assertNotNull(mr); | ||
} | ||
} |
Oops, something went wrong.