├── spring-library ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── de │ │ │ └── jonashackt │ │ │ └── library │ │ │ └── spring │ │ │ ├── FooLibrary.java │ │ │ ├── FooLibraryConfiguration.java │ │ │ ├── domain │ │ │ └── FooProduct.java │ │ │ ├── service │ │ │ └── FooLibraryService.java │ │ │ └── repository │ │ │ └── FooProductRepository.java │ └── test │ │ └── java │ │ └── de │ │ └── jonashackt │ │ └── library │ │ └── spring │ │ └── FooLibraryTest.java └── pom.xml ├── spring-library-user ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── de │ │ │ └── jonashackt │ │ │ └── spring │ │ │ └── user │ │ │ └── SpringLibraryUserApplication.java │ └── test │ │ └── java │ │ └── de │ │ └── jonashackt │ │ └── spring │ │ └── user │ │ └── SpringLibraryUserApplicationTests.java └── pom.xml ├── .travis.yml ├── README.md ├── .gitignore ├── pom.xml └── LICENSE /spring-library/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /spring-library-user/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - openjdk8 4 | 5 | script: mvn clean install 6 | -------------------------------------------------------------------------------- /spring-library/src/main/java/de/jonashackt/library/spring/FooLibrary.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.library.spring; 2 | 3 | /** 4 | * This is the entry point to our library. 5 | */ 6 | public interface FooLibrary { 7 | double calculateProducts(); 8 | } 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # spring-boot-library 2 | Example project showing how a Spring Boot app can use a library that´s build with Spring itself 3 | 4 | [![Build Status](https://travis-ci.org/jonashackt/spring-boot-library.svg?branch=master)](https://travis-ci.org/jonashackt/spring-boot-library) -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Package Files # 4 | *.jar 5 | *.war 6 | *.ear 7 | 8 | # Eclipse # 9 | .settings 10 | .project 11 | .classpath 12 | .studio 13 | target 14 | 15 | # Apple # 16 | .DS_Store 17 | 18 | # Intellij # 19 | .idea 20 | *.iml 21 | *.log 22 | 23 | # logback 24 | logback.out.xml -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | de.jonashackt 7 | spring-boot-library-build-all-projects 8 | 0.0.1-SNAPSHOT 9 | pom 10 | 11 | 12 | spring-library 13 | spring-library-user 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /spring-library/src/main/java/de/jonashackt/library/spring/FooLibraryConfiguration.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.library.spring; 2 | 3 | import de.jonashackt.library.spring.service.FooLibraryService; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.ComponentScan; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | @Configuration 9 | @ComponentScan("de.jonashackt.library.spring") 10 | public class FooLibraryConfiguration { 11 | 12 | @Bean 13 | public FooLibrary fooLibrary() { 14 | return new FooLibraryService(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /spring-library/src/main/java/de/jonashackt/library/spring/domain/FooProduct.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.library.spring.domain; 2 | 3 | public class FooProduct { 4 | 5 | private String name; 6 | private double price; 7 | 8 | public FooProduct(String name, double price) { 9 | this.name = name; 10 | this.price = price; 11 | } 12 | 13 | public double getPrice() { 14 | return price; 15 | } 16 | 17 | public void setPrice(double price) { 18 | this.price = price; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public void setName(String name) { 26 | this.name = name; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-library/src/main/java/de/jonashackt/library/spring/service/FooLibraryService.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.library.spring.service; 2 | 3 | import de.jonashackt.library.spring.FooLibrary; 4 | import de.jonashackt.library.spring.domain.FooProduct; 5 | import de.jonashackt.library.spring.repository.FooProductRepository; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Component; 8 | 9 | @Component 10 | public class FooLibraryService implements FooLibrary { 11 | 12 | @Autowired 13 | private FooProductRepository fooProductRepository; 14 | 15 | @Override 16 | public double calculateProducts() { 17 | return fooProductRepository.getProducts().stream().mapToDouble((FooProduct product) -> product.getPrice()).sum(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring-library/src/main/java/de/jonashackt/library/spring/repository/FooProductRepository.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.library.spring.repository; 2 | 3 | import de.jonashackt.library.spring.domain.FooProduct; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | @Repository 10 | public class FooProductRepository { 11 | 12 | private List products = Arrays.asList( 13 | new FooProduct("Product a", 23.6), 14 | new FooProduct("Product b", 45.8), 15 | new FooProduct("Product c", 67.9)); 16 | 17 | 18 | public List getProducts() { 19 | return products; 20 | } 21 | 22 | public void setProducts(List products) { 23 | this.products = products; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Jonas Hecht 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /spring-library/src/test/java/de/jonashackt/library/spring/FooLibraryTest.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.library.spring; 2 | 3 | import de.jonashackt.library.spring.service.FooLibraryService; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.context.annotation.Import; 9 | import org.springframework.test.context.ContextConfiguration; 10 | import org.springframework.test.context.junit4.SpringRunner; 11 | 12 | import static org.hamcrest.Matchers.equalTo; 13 | import static org.hamcrest.Matchers.is; 14 | import static org.junit.Assert.assertThat; 15 | 16 | 17 | @RunWith(SpringRunner.class) 18 | @ContextConfiguration 19 | @Import(FooLibraryConfiguration.class) 20 | public class FooLibraryTest { 21 | 22 | @Autowired 23 | private FooLibrary fooLibrary; 24 | 25 | @Test 26 | public void 27 | calculate_products_correctly() { 28 | double productPrice = fooLibrary.calculateProducts(); 29 | 30 | assertThat(productPrice, is(equalTo(137.3))); 31 | } 32 | } -------------------------------------------------------------------------------- /spring-library-user/src/test/java/de/jonashackt/spring/user/SpringLibraryUserApplicationTests.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.spring.user; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.boot.test.web.client.TestRestTemplate; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | import static org.hamcrest.Matchers.equalTo; 11 | import static org.hamcrest.Matchers.is; 12 | import static org.junit.Assert.assertThat; 13 | 14 | @RunWith(SpringRunner.class) 15 | @SpringBootTest( 16 | classes = SpringLibraryUserApplication.class, 17 | webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, 18 | properties = "server.port = 8080" 19 | ) 20 | public class SpringLibraryUserApplicationTests { 21 | 22 | @Test 23 | public void calculate_Products_With_FooLibrary() { 24 | 25 | TestRestTemplate restTemplate = new TestRestTemplate(); 26 | 27 | String response = restTemplate.getForObject("http://localhost:8080/productcalc", String.class); 28 | 29 | assertThat(response, is(equalTo(SpringLibraryUserApplication.REST_SERVICE_RESPONSE + "137.3"))); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /spring-library-user/src/main/java/de/jonashackt/spring/user/SpringLibraryUserApplication.java: -------------------------------------------------------------------------------- 1 | package de.jonashackt.spring.user; 2 | 3 | import de.jonashackt.library.spring.FooLibrary; 4 | import de.jonashackt.library.spring.FooLibraryConfiguration; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | import org.springframework.context.ApplicationContext; 9 | import org.springframework.context.annotation.Import; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import java.util.Arrays; 14 | 15 | @SpringBootApplication 16 | @Import(FooLibraryConfiguration.class) 17 | @RestController("/productcalc") 18 | public class SpringLibraryUserApplication { 19 | 20 | @Autowired 21 | private FooLibrary fooLibrary; 22 | 23 | public static final String REST_SERVICE_RESPONSE = "Nice to have you here! I calculated our Products prices for you: "; 24 | 25 | public static void main(String[] args) { 26 | SpringApplication.run(SpringLibraryUserApplication.class, args); 27 | } 28 | 29 | @RequestMapping 30 | public String calc() { 31 | System.out.println("Rocking the Libray usage :) !"); 32 | return REST_SERVICE_RESPONSE + 33 | String.valueOf(fooLibrary.calculateProducts()); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /spring-library-user/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | de.jonashackt.spring.user 7 | spring-library-user 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-library-user 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.4.3.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | de.jonashackt.library.spring 30 | spring-library 31 | 0.0.1-SNAPSHOT 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-web 37 | 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-devtools 42 | runtime 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-starter-test 47 | test 48 | 49 | 50 | 51 | 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-maven-plugin 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /spring-library/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | de.jonashackt.library.spring 7 | spring-library 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | 12 | UTF-8 13 | UTF-8 14 | 1.8 15 | 1.8 16 | 1.8 17 | 18 | 19 | 20 | 21 | 22 | org.springframework 23 | spring-context 24 | 4.3.5.RELEASE 25 | 26 | 27 | 28 | 29 | org.springframework 30 | spring-core 31 | 4.3.5.RELEASE 32 | 33 | 34 | 35 | 36 | org.springframework 37 | spring-beans 38 | 4.3.5.RELEASE 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-starter-test 44 | 1.4.3.RELEASE 45 | test 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.apache.maven.plugins 53 | maven-jar-plugin 54 | 3.0.2 55 | 56 | 57 | 58 | 59 | 60 | 61 | --------------------------------------------------------------------------------