├── .gitignore ├── README.md ├── core-module ├── .gitignore ├── src │ ├── main │ │ ├── java │ │ │ └── io │ │ │ │ └── manco │ │ │ │ └── maxim │ │ │ │ └── sbmm │ │ │ │ └── core │ │ │ │ ├── CoreApplication.java │ │ │ │ ├── repository │ │ │ │ └── MyEntityRepository.java │ │ │ │ ├── service │ │ │ │ ├── EntityService.java │ │ │ │ └── MyEntityServiceImpl.java │ │ │ │ └── domain │ │ │ │ └── MyEntity.java │ │ └── resources │ │ │ ├── config │ │ │ └── application.yml │ │ │ └── db │ │ │ └── changelog │ │ │ └── master.xml │ └── test │ │ └── java │ │ └── io │ │ └── manco │ │ └── maxim │ │ └── sbmm │ │ └── core │ │ ├── ContextAwareTest.java │ │ └── service │ │ ├── EntityServiceTest.java │ │ └── EntityServiceIntegrationTest.java └── pom.xml ├── web-module ├── .gitignore ├── src │ └── main │ │ ├── resources │ │ └── application.yml │ │ └── java │ │ └── io │ │ └── manco │ │ └── maxim │ │ └── sbmm │ │ └── web │ │ └── WebApplication.java └── pom.xml └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | /.settings/ 2 | /.project 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # spring-boot-multi-module 2 | Spring Boot Multi Module Project 3 | -------------------------------------------------------------------------------- /core-module/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /.settings/ 3 | /.classpath 4 | /.project 5 | -------------------------------------------------------------------------------- /web-module/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /.settings/ 3 | /.classpath 4 | /.project 5 | -------------------------------------------------------------------------------- /web-module/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | data: 3 | rest: 4 | max-page-size: 20 5 | -------------------------------------------------------------------------------- /core-module/src/main/java/io/manco/maxim/sbmm/core/CoreApplication.java: -------------------------------------------------------------------------------- 1 | package io.manco.maxim.sbmm.core; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.data.jpa.repository.config.EnableJpaAuditing; 5 | 6 | @EnableJpaAuditing 7 | @SpringBootApplication 8 | public class CoreApplication { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /core-module/src/main/java/io/manco/maxim/sbmm/core/repository/MyEntityRepository.java: -------------------------------------------------------------------------------- 1 | package io.manco.maxim.sbmm.core.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import io.manco.maxim.sbmm.core.domain.MyEntity; 6 | 7 | public interface MyEntityRepository extends JpaRepository { 8 | 9 | 10 | 11 | } 12 | -------------------------------------------------------------------------------- /core-module/src/main/java/io/manco/maxim/sbmm/core/service/EntityService.java: -------------------------------------------------------------------------------- 1 | package io.manco.maxim.sbmm.core.service; 2 | 3 | import java.util.Collection; 4 | 5 | import io.manco.maxim.sbmm.core.domain.MyEntity; 6 | 7 | public interface EntityService { 8 | 9 | MyEntity save(MyEntity entity); 10 | 11 | MyEntity find(Long id); 12 | 13 | Collection findAll(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /web-module/src/main/java/io/manco/maxim/sbmm/web/WebApplication.java: -------------------------------------------------------------------------------- 1 | package io.manco.maxim.sbmm.web; 2 | 3 | import org.springframework.boot.Banner; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.builder.SpringApplicationBuilder; 6 | 7 | import io.manco.maxim.sbmm.core.CoreApplication; 8 | 9 | @SpringBootApplication 10 | public class WebApplication { 11 | 12 | public static void main(String[] args) { 13 | new SpringApplicationBuilder() 14 | .bannerMode(Banner.Mode.CONSOLE) 15 | .sources(CoreApplication.class, WebApplication.class) 16 | .run(args); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /core-module/src/main/resources/config/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | jpa: 3 | properties: 4 | hibernate: 5 | hbm2ddl.auto: validate 6 | show_sql: false 7 | format_sql: false 8 | use_sql_comments: false 9 | liquibase: 10 | change-log: classpath:/db/changelog/master.xml 11 | 12 | --- 13 | 14 | spring: 15 | profiles: mysql 16 | jpa: 17 | properties: 18 | hibernate: 19 | dialect: org.hibernate.dialect.MySQL5InnoDBDialect 20 | datasource: 21 | url: jdbc:mysql://localhost/sbmm 22 | username: sbmm 23 | password: sbmm 24 | 25 | --- 26 | 27 | spring: 28 | profiles: embeddeddb 29 | jpa: 30 | properties: 31 | hibernate: 32 | dialect: org.hibernate.dialect.H2Dialect 33 | datasource: 34 | url: jdbc:h2:mem:sbmm -------------------------------------------------------------------------------- /core-module/src/main/java/io/manco/maxim/sbmm/core/service/MyEntityServiceImpl.java: -------------------------------------------------------------------------------- 1 | package io.manco.maxim.sbmm.core.service; 2 | 3 | import java.util.Collection; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | import org.springframework.transaction.annotation.Transactional; 8 | 9 | import io.manco.maxim.sbmm.core.domain.MyEntity; 10 | import io.manco.maxim.sbmm.core.repository.MyEntityRepository; 11 | 12 | @Service 13 | public class MyEntityServiceImpl implements EntityService { 14 | 15 | @Autowired 16 | private MyEntityRepository repository; 17 | 18 | @Override 19 | @Transactional(readOnly = false) 20 | public MyEntity save(MyEntity entity) { 21 | return repository.save(entity); 22 | } 23 | 24 | @Override 25 | public MyEntity find(Long id) { 26 | return repository.findOne(id); 27 | } 28 | 29 | @Override 30 | public Collection findAll() { 31 | return repository.findAll(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /core-module/src/test/java/io/manco/maxim/sbmm/core/ContextAwareTest.java: -------------------------------------------------------------------------------- 1 | package io.manco.maxim.sbmm.core; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 6 | import org.springframework.test.annotation.Rollback; 7 | import org.springframework.test.context.ActiveProfiles; 8 | import org.springframework.test.context.TestExecutionListeners; 9 | import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | import org.springframework.test.context.transaction.TransactionalTestExecutionListener; 12 | import org.springframework.transaction.annotation.Transactional; 13 | 14 | @Rollback 15 | @Transactional 16 | @ActiveProfiles({"embeddeddb"}) 17 | @RunWith(SpringJUnit4ClassRunner.class) 18 | @TestExecutionListeners(TransactionalTestExecutionListener.class) 19 | @SpringBootTest(webEnvironment = WebEnvironment.NONE, classes = CoreApplication.class) 20 | public abstract class ContextAwareTest extends AbstractJUnit4SpringContextTests { } 21 | -------------------------------------------------------------------------------- /core-module/src/test/java/io/manco/maxim/sbmm/core/service/EntityServiceTest.java: -------------------------------------------------------------------------------- 1 | package io.manco.maxim.sbmm.core.service; 2 | 3 | import static org.mockito.Mockito.verify; 4 | import static org.mockito.MockitoAnnotations.initMocks; 5 | 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.mockito.InjectMocks; 9 | import org.mockito.Mock; 10 | 11 | import io.manco.maxim.sbmm.core.domain.MyEntity; 12 | import io.manco.maxim.sbmm.core.repository.MyEntityRepository; 13 | 14 | public class EntityServiceTest { 15 | 16 | @Mock 17 | private MyEntityRepository repository; 18 | 19 | @InjectMocks 20 | private MyEntityServiceImpl service; 21 | 22 | @Before 23 | public void initialize() { 24 | initMocks(this); 25 | } 26 | 27 | @Test 28 | public void save() { 29 | MyEntity entity = new MyEntity("test", "test"); 30 | service.save(entity); 31 | verify(repository).save(entity); 32 | } 33 | 34 | @Test 35 | public void find() { 36 | Long id = 1L; 37 | service.find(id); 38 | verify(repository).findOne(id); 39 | } 40 | 41 | @Test 42 | public void findAll() { 43 | service.findAll(); 44 | verify(repository).findAll(); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | io.manco.maxim 5 | spring-boot-multi-module 6 | 0.0.1-SNAPSHOT 7 | pom 8 | 9 | org.springframework.boot 10 | spring-boot-starter-parent 11 | 1.5.2.RELEASE 12 | 13 | 14 | 1.8 15 | 16 | 17 | core-module 18 | web-module 19 | 20 | 21 | 22 | 23 | io.manco.maxim 24 | core-module 25 | ${project.version} 26 | 27 | 28 | com.mattbertolini 29 | liquibase-slf4j 30 | 2.0.0 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /core-module/src/main/resources/db/changelog/master.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /web-module/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | io.manco.maxim 6 | spring-boot-multi-module 7 | 0.0.1-SNAPSHOT 8 | 9 | web-module 10 | 11 | 12 | io.manco.maxim 13 | core-module 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-web 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-tomcat 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-thymeleaf 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-data-rest 30 | 31 | 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-maven-plugin 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /core-module/src/test/java/io/manco/maxim/sbmm/core/service/EntityServiceIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package io.manco.maxim.sbmm.core.service; 2 | 3 | 4 | import static org.hamcrest.core.IsEqual.equalTo; 5 | import static org.hamcrest.core.IsNull.notNullValue; 6 | import static org.hamcrest.core.IsNull.nullValue; 7 | import static org.junit.Assert.assertThat; 8 | 9 | import java.util.ArrayList; 10 | import java.util.Collection; 11 | 12 | import org.junit.Test; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.test.annotation.Rollback; 15 | import org.springframework.transaction.annotation.Transactional; 16 | 17 | import io.manco.maxim.sbmm.core.ContextAwareTest; 18 | import io.manco.maxim.sbmm.core.domain.MyEntity; 19 | 20 | public class EntityServiceIntegrationTest extends ContextAwareTest { 21 | 22 | @Autowired 23 | private EntityService service; 24 | 25 | @Test 26 | @Rollback 27 | @Transactional(readOnly = false) 28 | public void save() { 29 | MyEntity entity = new MyEntity("test", "test"); 30 | assertThat(entity.getId(), nullValue()); 31 | entity = service.save(entity); 32 | assertThat(entity.getId(), notNullValue()); 33 | } 34 | 35 | @Test 36 | @Rollback 37 | @Transactional(readOnly = false) 38 | public void find() { 39 | MyEntity entity = service.save(new MyEntity("test", "test")); 40 | entity = service.find(entity.getId()); 41 | assertThat(entity, notNullValue()); 42 | } 43 | 44 | @Test 45 | @Rollback 46 | @Transactional(readOnly = false) 47 | public void findAll() { 48 | Collection entities = new ArrayList<>(); 49 | entities.add(service.save(new MyEntity("test", "test"))); 50 | entities.add(service.save(new MyEntity("test2", "test"))); 51 | entities.add(service.save(new MyEntity("test3", "test"))); 52 | Collection all = service.findAll(); 53 | assertThat(all, equalTo(entities)); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /core-module/src/main/java/io/manco/maxim/sbmm/core/domain/MyEntity.java: -------------------------------------------------------------------------------- 1 | package io.manco.maxim.sbmm.core.domain; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | import javax.persistence.Column; 7 | import javax.persistence.Entity; 8 | import javax.persistence.EntityListeners; 9 | import javax.persistence.GeneratedValue; 10 | import javax.persistence.Id; 11 | 12 | import org.springframework.data.annotation.CreatedDate; 13 | import org.springframework.data.annotation.LastModifiedDate; 14 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; 15 | 16 | @Entity 17 | @EntityListeners(AuditingEntityListener.class) 18 | public class MyEntity implements Serializable { 19 | 20 | private static final long serialVersionUID = 5104355377350251539L; 21 | 22 | @Id 23 | @GeneratedValue 24 | private Long id; 25 | 26 | @Column 27 | private String name; 28 | 29 | @Column 30 | private String value; 31 | 32 | @CreatedDate 33 | private Date creationDate; 34 | 35 | @LastModifiedDate 36 | private Date modificationDate; 37 | 38 | public MyEntity() { } 39 | 40 | public MyEntity(String name, String value) { 41 | this.name = name; 42 | this.value = value; 43 | } 44 | 45 | public Long getId() { 46 | return id; 47 | } 48 | 49 | public String getName() { 50 | return name; 51 | } 52 | 53 | public String getValue() { 54 | return value; 55 | } 56 | 57 | public Date getCreationDate() { 58 | return creationDate; 59 | } 60 | 61 | public Date getModificationDate() { 62 | return modificationDate; 63 | } 64 | 65 | @Override 66 | public int hashCode() { 67 | final int prime = 31; 68 | int result = 1; 69 | result = prime * result + ((id == null) ? 0 : id.hashCode()); 70 | return result; 71 | } 72 | 73 | @Override 74 | public boolean equals(Object obj) { 75 | if (this == obj) 76 | return true; 77 | if (obj == null) 78 | return false; 79 | if (getClass() != obj.getClass()) 80 | return false; 81 | MyEntity other = (MyEntity) obj; 82 | if (id == null) { 83 | if (other.id != null) 84 | return false; 85 | } else if (!id.equals(other.id)) 86 | return false; 87 | return true; 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /core-module/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | io.manco.maxim 6 | spring-boot-multi-module 7 | 0.0.1-SNAPSHOT 8 | 9 | core-module 10 | 11 | 12 | org.springframework.boot 13 | spring-boot-starter-data-jpa 14 | 15 | 16 | com.h2database 17 | h2 18 | 19 | 20 | mysql 21 | mysql-connector-java 22 | 23 | 24 | org.liquibase 25 | liquibase-core 26 | 27 | 28 | com.mattbertolini 29 | liquibase-slf4j 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-test 34 | test 35 | 36 | 37 | 38 | 39 | 40 | org.apache.maven.plugins 41 | maven-surefire-plugin 42 | 43 | 44 | **/*IntegrationTest.java 45 | 46 | 47 | 48 | 49 | org.apache.maven.plugins 50 | maven-failsafe-plugin 51 | 52 | 53 | integration-tests 54 | 55 | integration-test 56 | verify 57 | 58 | 59 | 60 | **/*IntegrationTest.java 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | --------------------------------------------------------------------------------