model) {
60 | throw new RuntimeException("Foo");
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/application/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | # Application messages
2 | application.message = Hello User!
3 | dummy.type = type-inside-the-war
4 |
5 | # Spring Thymeleaf config
6 | spring.thymeleaf.cache = false
7 |
8 |
--------------------------------------------------------------------------------
/application/src/main/resources/templates/welcome/show.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Spring Boot Multimodule
5 |
6 |
7 |
8 |
9 | Message:
10 |
11 |
12 |
13 | Your account:
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/configuration/settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
21 |
22 |
46 |
49 |
55 |
56 |
64 |
65 |
72 |
73 |
78 |
79 |
83 |
84 |
85 |
90 |
91 |
105 |
106 |
107 |
111 |
112 |
125 |
126 |
133 |
134 |
135 |
146 |
147 |
159 |
160 |
161 |
182 |
183 |
212 |
213 |
247 |
248 |
249 |
257 |
258 |
--------------------------------------------------------------------------------
/model/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | sample.multimodule
6 | sample.multimodule
7 | 0.0.1-SNAPSHOT
8 |
9 | sample.multimodule.model
10 | jar
11 | Project Module - Model
12 | Module that contains all Entities and Visual Objects to be used in the project. It doesn't have any dependencies.
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/model/src/main/java/sample/multimodule/domain/entity/Account.java:
--------------------------------------------------------------------------------
1 | package sample.multimodule.domain.entity;
2 |
3 | import javax.persistence.Entity;
4 | import javax.persistence.Id;
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.GenerationType;
7 |
8 |
9 | @Entity
10 | public class Account {
11 |
12 | @Id
13 | @GeneratedValue(strategy = GenerationType.AUTO)
14 | private Long id;
15 |
16 | private String number;
17 |
18 | private String type;
19 |
20 | private String creditCardNumber;
21 |
22 | /**
23 | * Create an empty account.
24 | */
25 | public Account() {
26 |
27 | }
28 |
29 | /**
30 | * Create a new account.
31 | *
32 | * @param number
33 | * the account number
34 | * @param id
35 | * the account id
36 | */
37 | public Account(Long id, String number) {
38 | this.number = number;
39 | this.id = id;
40 | }
41 |
42 | public Long getId() {
43 | return id;
44 | }
45 |
46 | public void setId(Long id) {
47 | this.id = id;
48 | }
49 |
50 | public String getNumber() {
51 | return number;
52 | }
53 |
54 | public void setNumber(String number) {
55 | this.number = number;
56 | }
57 |
58 | public String getType() {
59 | return type;
60 | }
61 |
62 | public void setType(String type) {
63 | this.type = type;
64 | }
65 |
66 | public String getCreditCardNumber() {
67 | return creditCardNumber;
68 | }
69 |
70 | public void setCreditCardNumber(String creditCardNumber) {
71 | this.creditCardNumber = creditCardNumber;
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
6 |
7 | io.spring.platform
8 | platform-bom
9 | 2.0.1.RELEASE
10 |
11 | sample.multimodule
12 | sample.multimodule
13 | 0.0.1-SNAPSHOT
14 | pom
15 | Parent - Pom Aggregator
16 | This pom is a maven aggregator that contains all application modules. Also, include all
17 | common dependencies needed by more than one module. Dependencies are defined without version because
18 | this project has defined Spring IO Platform as parent.
19 |
20 |
21 | 1.6
22 |
23 |
24 |
25 | model
26 | repository
27 | service-api
28 | service-impl
29 | application
30 |
31 |
32 |
33 |
34 |
35 |
36 | org.springframework.boot
37 | spring-boot-starter
38 |
39 |
40 | org.springframework.boot
41 | spring-boot-starter-data-jpa
42 |
43 |
44 | org.springframework.boot
45 | spring-boot-starter-test
46 | test
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/repository/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | sample.multimodule
6 | sample.multimodule
7 | 0.0.1-SNAPSHOT
8 |
9 | sample.multimodule.repository
10 | jar
11 | Project Module - Repository
12 | Module that contains all repositories to be used in the project. Depends of Model Module.
13 |
14 |
15 |
16 |
17 | sample.multimodule
18 | sample.multimodule.model
19 | ${project.version}
20 |
21 |
22 |
23 |
24 | org.hsqldb
25 | hsqldb
26 | runtime
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/repository/src/main/java/sample/multimodule/repository/AccountRepository.java:
--------------------------------------------------------------------------------
1 | package sample.multimodule.repository;
2 |
3 | import org.springframework.data.domain.*;
4 | import org.springframework.data.repository.*;
5 | import org.springframework.stereotype.Repository;
6 |
7 | import sample.multimodule.domain.entity.Account;
8 |
9 | @Repository
10 | public interface AccountRepository extends CrudRepository {
11 |
12 | Account findByNumber(String number);
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/service-api/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | sample.multimodule
6 | sample.multimodule
7 | 0.0.1-SNAPSHOT
8 |
9 | sample.multimodule.service.api
10 | jar
11 | Project Module - Service API
12 | Module that contains API of all project services. Depends of Model Module.
13 |
14 |
15 |
16 |
17 |
18 | sample.multimodule
19 | sample.multimodule.model
20 | ${project.version}
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/service-api/src/main/java/sample/multimodule/service/api/AccountNotFoundException.java:
--------------------------------------------------------------------------------
1 | package sample.multimodule.service.api;
2 |
3 | public class AccountNotFoundException extends RuntimeException {
4 |
5 | private static final long serialVersionUID = -3891534644498426670L;
6 |
7 | public AccountNotFoundException(String accountId) {
8 | super("No such account with id: " + accountId);
9 | }
10 | }
11 |
12 |
--------------------------------------------------------------------------------
/service-api/src/main/java/sample/multimodule/service/api/AccountService.java:
--------------------------------------------------------------------------------
1 | package sample.multimodule.service.api;
2 |
3 | import java.util.List;
4 | import sample.multimodule.domain.entity.Account;
5 |
6 | public interface AccountService {
7 |
8 | /**
9 | * Finds the account with the provided account number.
10 | *
11 | * @param number The account number
12 | * @return The account
13 | * @throws AccountNotFoundException If no such account exists.
14 | */
15 | Account findOne(String number) throws AccountNotFoundException;
16 |
17 | /**
18 | * Creates a new account.
19 | *
20 | * @param number
21 | * @return created account
22 | */
23 | Account createAccountByNumber(String number);
24 | }
25 |
--------------------------------------------------------------------------------
/service-impl/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | sample.multimodule
6 | sample.multimodule
7 | 0.0.1-SNAPSHOT
8 |
9 | sample.multimodule.service.impl
10 | jar
11 | Project Module - Service Implementation
12 | Module that contains services implementation defined on Service API module. Depends of Repository Module and
13 | Service API Module.
14 |
15 |
16 |
17 |
18 |
19 | sample.multimodule
20 | sample.multimodule.repository
21 | ${project.version}
22 |
23 |
24 | sample.multimodule
25 | sample.multimodule.service.api
26 | ${project.version}
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/service-impl/src/main/java/sample/multimodule/service/impl/AccountServiceImpl.java:
--------------------------------------------------------------------------------
1 | package sample.multimodule.service.impl;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.springframework.beans.factory.annotation.Value;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.stereotype.Service;
9 |
10 | import sample.multimodule.domain.entity.Account;
11 | import sample.multimodule.repository.AccountRepository;
12 | import sample.multimodule.service.api.AccountService;
13 | import sample.multimodule.service.api.AccountNotFoundException;
14 |
15 | @Service
16 | public class AccountServiceImpl implements AccountService {
17 |
18 | @Value("${dummy.type}")
19 | private String dummyType;
20 |
21 | @Autowired
22 | private AccountRepository accountRepository;
23 |
24 | /**
25 | * {@inheritDoc}
26 | *
27 | * Dummy method for testing purposes.
28 | *
29 | * @param number The account number. Set 0000 to get an {@link AccountNotFoundException}
30 | */
31 | @Override
32 | public Account findOne(String number) throws AccountNotFoundException {
33 | if(number.equals("0000")) {
34 | throw new AccountNotFoundException("0000");
35 | }
36 |
37 | Account account = accountRepository.findByNumber(number);
38 | if(account == null){
39 | account = createAccountByNumber(number);
40 | }
41 |
42 | return account;
43 | }
44 |
45 | @Override
46 | public Account createAccountByNumber(String number) {
47 | Account account = new Account();
48 | account.setNumber(number);
49 | return accountRepository.save(account);
50 | }
51 |
52 | public String getDummyType() {
53 | return dummyType;
54 | }
55 |
56 | public void setDummyType(String dummyType) {
57 | this.dummyType = dummyType;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------