Skip to content

Commit

Permalink
Spring Boot 2.1.7 to 2.2.5
Browse files Browse the repository at this point in the history
Spring Cloud Greenwich.SR2 to Hoxton.SR2
Gradle 5.5.1 to 6.2.2
  • Loading branch information
jkazama committed Mar 5, 2020
1 parent cea5143 commit 0f888fe
Show file tree
Hide file tree
Showing 17 changed files with 123 additions and 119 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sample-boot-micro

### はじめに

[Spring Cloud Netflix](https://cloud.spring.io/spring-cloud-netflix/) の仕組みを利用したマイクロサービス実装サンプルです。
[Spring Cloud](https://spring.io/projects/spring-cloud) の仕組みを利用したマイクロサービス実装サンプルです。

[Spring Boot](http://projects.spring.io/spring-boot/) / [Spring Security](http://projects.spring.io/spring-security/) / [Hibernate ORM](http://hibernate.org/orm/) を元にしたマルチプロジェクト下での DDD サンプルとしても利用できます。

Expand Down Expand Up @@ -224,8 +224,8 @@ Spring Boot では Executable Jar ( ライブラリや静的リソースなど

| ライブラリ | バージョン | 用途/追加理由 |
| ----------------------- | -------- | ------------- |
| `spring-cloud` | Greenwich.+ | Spring Cloud 基盤 |
| `spring-boot-starter-*` | 2.1.+ | Spring Boot 基盤 (actuator/security/aop/cache/data-jpa/web) |
| `spring-cloud` | Hoxton.+ | Spring Cloud 基盤 |
| `spring-boot-starter-*` | 2.2.+ | Spring Boot 基盤 (actuator/security/aop/cache/data-jpa/web) |

> 実際の詳細な定義は `build.gradle` を参照してください
Expand Down
38 changes: 9 additions & 29 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
plugins {
id "org.springframework.boot" version "2.1.7.RELEASE"
id "io.spring.dependency-management" version "1.0.8.RELEASE"
id "org.springframework.boot" version "2.2.5.RELEASE"
id "io.spring.dependency-management" version "1.0.9.RELEASE"
}

ext.spring_cloud_version = "Greenwich.SR2"
ext['lombok.version'] = "1.18.8"
ext.spring_cloud_version = "Hoxton.SR2"
ext['lombok.version'] = "1.18.12"

allprojects {
repositories {
jcenter()
mavenCentral()
}
}

subprojects {
version = "2.1.7"
version = "2.2.5"

apply plugin: "java"
apply plugin: "org.springframework.boot"
Expand Down Expand Up @@ -61,14 +61,13 @@ subprojects {
implementation "org.springframework.boot:spring-boot-starter-cache"
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
implementation "org.springframework.boot:spring-boot-starter-web"
implementation "com.github.ben-manes.caffeine:caffeine"
implementation "org.ehcache:ehcache"
implementation "javax.cache:cache-api"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-hibernate5"
implementation "org.eclipse.collections:eclipse-collections:10.0.0"
implementation "org.eclipse.collections:eclipse-collections-api:10.0.0"
implementation "commons-io:commons-io:2.6"
implementation "org.apache.commons:commons-lang3"
implementation "com.ibm.icu:icu4j:64.2"
implementation "com.ibm.icu:icu4j:65.1"
implementation fileTree(dir: 'libs', includes: ['*.jar'])
runtime "com.h2database:h2"
testAnnotationProcessor "org.projectlombok:lombok"
Expand All @@ -77,25 +76,6 @@ subprojects {
}
}

project(':micro-app') {
dependencies {
implementation project(':micro-core')
}
}

project(':micro-asset') {
dependencies {
implementation project(':micro-core')
}
}

project(':micro-web') {
dependencies {
implementation project(':micro-core')
implementation project(':micro-asset')
}
}

wrapper {
gradleVersion = "5.5.1"
gradleVersion = "6.2.2"
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
2 changes: 1 addition & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem http://www.apache.org/licenses/LICENSE-2.0
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
4 changes: 4 additions & 0 deletions micro-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ bootJar {
mainClassName = 'sample.MicroApp'
classifier = 'exec'
}

dependencies {
implementation project(':micro-core')
}
12 changes: 10 additions & 2 deletions micro-app/src/main/resources/application-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
spring:
profiles: app
application.name: micro-app
boot.admin:
discovery.converter.management-context-path: ${management.endpoints.web.base-path}

server:
port: 8090
Expand All @@ -13,3 +11,13 @@ extension:
default.jpa.hibernate.ddl-auto: create-drop
system.jpa.hibernate.ddl-auto: create-drop
datafixture.enabled: true

---
spring:
profiles: production

extension:
datasource:
default.jpa.hibernate.ddl-auto: none
system.jpa.hibernate.ddl-auto: none
datafixture.enabled: false
4 changes: 4 additions & 0 deletions micro-asset/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ bootJar {
classifier = 'exec'
}
jar.enabled=true

dependencies {
implementation project(':micro-core')
}
16 changes: 12 additions & 4 deletions micro-asset/src/main/resources/application-asset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ server:
extension:
datasource:
asset:
url: jdbc:h2:tcp://localhost:9092/mem:asset
username:
password:
url: ${DB_ASSET_JDBC_URL:jdbc:h2:tcp://localhost:9092/mem:asset}
username: ${DB_ASSET_JDBC_USERNAME:}
password: ${DB_ASSET_JDBC_USERNAME:}
jpa:
package-to-scan: sample.microasset.model.asset
hibernate.ddl-auto: create-drop
datafixture.enabled: true



---
spring:
profiles: production

extension:
datasource:
asset.jpa.hibernate.ddl-auto: none
datafixture.enabled: false
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import sample.model.account.*;
import sample.model.master.SelfFiAccount;

//low: 簡易な正常系検証が中心。依存するCashflow/CashBalanceの単体検証パスを前提。
// low: 簡易な正常系検証が中心。依存するCashflow/CashBalanceの単体検証パスを前提。
public class CashInOutTest extends EntityTestSupport {

private static final String ccy = "JPY";
Expand Down Expand Up @@ -47,7 +47,7 @@ public void before() {
LocalDate basePlus2Day = businessDay.day(2);
tx(() -> {
fixturesAsset.cio(accId, "300", true).save(rep);
//low: ちゃんとやると大変なので最低限の検証
// low: ちゃんとやると大変なので最低限の検証
assertThat(
CashInOut.find(rep, findParam(baseDay, basePlus1Day)),
hasSize(1));
Expand All @@ -68,7 +68,6 @@ private FindCashInOut findParam(LocalDate fromDay, LocalDate toDay, ActionStatus
}

@Test
@SuppressWarnings("unchecked")
public void 振込出金依頼をする() {
LocalDate baseDay = businessDay.day();
LocalDate basePlus3Day = businessDay.day(3);
Expand All @@ -90,7 +89,8 @@ private FindCashInOut findParam(LocalDate fromDay, LocalDate toDay, ActionStatus
}

// 通常の出金依頼
CashInOut normal = CashInOut.withdraw(rep, rep, businessDay, new RegCashOut(accId, ccy, new BigDecimal("300")));
CashInOut normal = CashInOut.withdraw(rep, rep, businessDay,
new RegCashOut(accId, ccy, new BigDecimal("300")));
assertThat(normal, allOf(
hasProperty("accountId", is(accId)), hasProperty("currency", is(ccy)),
hasProperty("absAmount", is(new BigDecimal(300))), hasProperty("withdrawal", is(true)),
Expand Down Expand Up @@ -157,7 +157,6 @@ private FindCashInOut findParam(LocalDate fromDay, LocalDate toDay, ActionStatus
}

@Test
@SuppressWarnings("unchecked")
public void 発生日を迎えた振込入出金をキャッシュフロー登録する() {
LocalDate baseDay = businessDay.day();
LocalDate basePlus3Day = businessDay.day(3);
Expand Down
12 changes: 6 additions & 6 deletions micro-core/src/main/java/sample/api/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sample.context.rest.RestInvoker;

/**
* Spring Cloud Netflix 標準の API クライアント要求アプローチをサポートします。
* Spring Cloud 標準の API クライアント要求アプローチをサポートします。
* <p>API クライアント側の Facade で本コンポーネントから RestInvoker を取得して実行してください。
*/
public class ApiClient {
Expand All @@ -22,14 +22,14 @@ public ApiClient(RestTemplate template, ObjectMapper mapper) {
this.mapper = mapper;
}

/** Ribbon を用いた RestInvoker を返します。 */
public RestInvoker invoker(String applicationName, String rootPath) {
return new RestInvoker(this.template, this.mapper, rootUrl(applicationName, rootPath));
/** RestInvoker を返します。 */
public RestInvoker invoker(String url, String rootPath) {
return new RestInvoker(this.template, this.mapper, rootUrl(url, rootPath));
}

/** API 接続先ルートとなる URL を返します。 */
private String rootUrl(String applicationName, String rootPath) {
return "http://" + applicationName + Optional.ofNullable(rootPath).orElse("");
private String rootUrl(String url, String rootPath) {
return url + Optional.ofNullable(rootPath).orElse("");
}

public static ApiClient of(RestTemplate template, ObjectMapper mapper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import javax.servlet.*;
import javax.servlet.http.*;

import org.eclipse.collections.impl.list.fixed.ArrayAdapter;
import org.springframework.beans.factory.annotation.*;
import org.springframework.boot.autoconfigure.web.servlet.*;
import org.springframework.context.MessageSource;
Expand Down Expand Up @@ -59,7 +58,7 @@ public class SecurityConfigurer extends WebSecurityConfigurerAdapter {
/** CORS利用時のフィルタ */
@Autowired(required = false)
private CorsFilter corsFilter;

/** 適用対象となる DistpatcherServlet 登録情報 */
@Autowired
@Qualifier(DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME)
Expand All @@ -68,54 +67,55 @@ public class SecurityConfigurer extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().mvcMatchers(
ArrayAdapter.adapt(props.auth().getIgnorePath())
.collect(dispatcherServletRegistration::getRelativePath)
.toArray(new String[0]));
Arrays.asList(props.auth().getIgnorePath())
.stream()
.map(dispatcherServletRegistration::getRelativePath)
.toArray(String[]::new));
}

@Override
protected void configure(HttpSecurity http) throws Exception {
// Target URL
http
.authorizeRequests()
.mvcMatchers(props.auth().getExcludesPath()).permitAll();
.authorizeRequests()
.mvcMatchers(props.auth().getExcludesPath()).permitAll();
if (this.props.auth().isEnabled()) {
http
.csrf().disable()
.authorizeRequests()
.mvcMatchers(props.auth().getPathAdmin()).hasRole("ADMIN")
.mvcMatchers(props.auth().getPath()).hasRole("USER");
.csrf().disable()
.authorizeRequests()
.mvcMatchers(props.auth().getPathAdmin()).hasRole("ADMIN")
.mvcMatchers(props.auth().getPath()).hasRole("USER");
} else {
http
.csrf().disable()
.authorizeRequests()
.mvcMatchers("/**").permitAll();
.csrf().disable()
.authorizeRequests()
.mvcMatchers("/**").permitAll();
}

// Common
http
.exceptionHandling().authenticationEntryPoint(entryPoint);
.exceptionHandling().authenticationEntryPoint(entryPoint);
http
.sessionManagement()
.maximumSessions(props.auth().getMaximumSessions())
.and()
.sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED);
.sessionManagement()
.maximumSessions(props.auth().getMaximumSessions())
.and()
.sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED);
http
.addFilterAfter(new ActorSessionFilter(actorSession), UsernamePasswordAuthenticationFilter.class);
.addFilterAfter(new ActorSessionFilter(actorSession), UsernamePasswordAuthenticationFilter.class);
if (corsFilter != null) {
http.addFilterBefore(corsFilter, LogoutFilter.class);
}

// login/logout
http
.formLogin().loginPage(props.auth().getLoginPath())
.usernameParameter(props.auth().getLoginKey()).passwordParameter(props.auth().getPasswordKey())
.successHandler(loginHandler).failureHandler(loginHandler)
.permitAll()
.and()
.logout().logoutUrl(props.auth().getLogoutPath())
.logoutSuccessHandler(loginHandler)
.permitAll();
.formLogin().loginPage(props.auth().getLoginPath())
.usernameParameter(props.auth().getLoginKey()).passwordParameter(props.auth().getPasswordKey())
.successHandler(loginHandler).failureHandler(loginHandler)
.permitAll()
.and()
.logout().logoutUrl(props.auth().getLogoutPath())
.logoutSuccessHandler(loginHandler)
.permitAll();
}

/**
Expand Down Expand Up @@ -174,7 +174,7 @@ public void commence(HttpServletRequest request, HttpServletResponse response,
writeReponseEmpty(response, HttpServletResponse.SC_UNAUTHORIZED, message);
}
}

private void writeReponseEmpty(HttpServletResponse response, int status, String message) throws IOException {
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
response.setStatus(status);
Expand All @@ -185,7 +185,7 @@ private void writeReponseEmpty(HttpServletResponse response, int status, String

/**
* SpringSecurityの認証情報(Authentication)とActorSessionを紐付けるServletFilter。
* <p>dummyLoginが有効な時は常にSecurityContextHolderへAuthenticationを紐付けます。
* <p>dummyLoginが有効な時は常にSecurityContextHolderへAuthenticationを紐付けます。
*/
@AllArgsConstructor
public static class ActorSessionFilter extends GenericFilterBean {
Expand Down Expand Up @@ -246,7 +246,7 @@ public void onAuthenticationFailure(HttpServletRequest request, HttpServletRespo
@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication)
throws IOException, ServletException {
throws IOException, ServletException {
if (response.isCommitted()) {
return;
}
Expand Down
Loading

0 comments on commit 0f888fe

Please sign in to comment.