Contenu connexe
Similaire à SpringOne Platform 2017報告会 メインプロジェクトのアップデート (20)
Plus de Takuya Iwatsuka (13)
SpringOne Platform 2017報告会 メインプロジェクトのアップデート
- 2. Copyright©2018 NTT corp. All Rights Reserved.
•
• 3
• L FDCa c
• ST L FD VC
• 56 N L C W
•
• 0: 56 76
• 0: .2 0:
• 06 0615:17
- 3. Copyright©2018 NTT corp. All Rights Reserved.
KFI
? 8 /4 4 D24C )
? 8 75B? C ( ) )
? 8 7 ) )
? 8 1 78?4 ( )
? 8 4 59 )
? 8 * )
? 8 . B D0 59 7C
7 3 C 1 *
- 8. Copyright©2018 NTT corp. All Rights Reserved.
. 0 0 0 . 2
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>
spring-boot-starter-data-mongodb
</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
0
- 9. Copyright©2018 NTT corp. All Rights Reserved.
0 2 F
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>
spring-boot-starter-data-mongodb-reactive
</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
0
.0 0 : C B A
- 12. Copyright©2018 NTT corp. All Rights Reserved.
- @ A - @ CF
@ @ , C A
A @
- @
- @ @
A @ CF
, - @ A
/ @
, C @ C A
1 ( )-
(22 ( -(2
1 ( )- - @ M IJH
- 13. Copyright©2018 NTT corp. All Rights Reserved.
• )( ) )
• 1 1 1
• 1
• 1 1 1 1
• 1 1 1 1
)( ( )( ) )
1 1
31 1
1
A 1
1
1 1 1
1
1 1
LT
1 RUM S WH
UP
1 1 1
1 1
1 AF
FE
- 15. Copyright©2018 NTT corp. All Rights Reserved.
• A
• -
• - :
• - A
• - :
FFF
)
A : 0 :
/ 1
5 A / 1
:. 0: 0 :
/ 1
A
FFF
R W
/ 1 S T
)
:
)
) (
h c IH L dg
- :5 - A E biea
0 : .0 AE0 0 A 0 :5 A E
- 16. Copyright©2018 NTT corp. All Rights Reserved.
. +
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
- 17. Copyright©2018 NTT corp. All Rights Reserved.
+ +
B A C
$ wget http://localhost:8080 --header='Accept: application/json
--2018-01-23 16:05:32-- http://localhost:8080/
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|::1|:8080... connected.
HTTP request sent, awaiting response... 401 Unauthorized
Username/Password Authentication Failed.
B A C: + + : F
- 18. Copyright©2018 NTT corp. All Rights Reserved.
@Configuration
@EnableWebFluxSecurity
public class SimpleSecurityConfig{
@Bean
public MapReactiveUserDetailsService userDetailsRepository() {
UserDetails user = User.withDefaultPasswordEncoder()
.username("user")
.password("password")
.roles("USER")
.build();
UserDetails admin = User.withDefaultPasswordEncoder()
.username("admin")
.password("admin")
.roles("ADMIN","USER")
.build();
return new MapReactiveUserDetailsService(user, admin);
}
( ) S F
( + ) W
) . S :
- 19. Copyright©2018 NTT corp. All Rights Reserved.
@Bean
public SecurityWebFilterChain springSecurityFilterChain(
ServerHttpSecurity http) {
http
.authorizeExchange()
.pathMatchers("/resources/**").permitAll()
.pathMatchers("/login").permitAll()
.pathMatchers("/admin").hasRole("ADMIN")
.anyExchange().authenticated()
.and()
.formLogin()
.loginPage("/login");
return http.build();
}
}
+ C :
+ + + +
+
- 20. Copyright©2018 NTT corp. All Rights Reserved.
•
• 2 0
• 2 0 / 2
• 2 0
• )/ 2 /)/ 2 )/ 2 / / /
• )
• 2 / ( 0
•
• 2 0
• 2 0 / 2
• 2 0
• 2 0
- 21. Copyright©2018 NTT corp. All Rights Reserved.
• , , , , , , , S
K / - NR
• C 2 2 B D
• D T B
• 21 2
• 1
• 2
•
- : , , T
- 22. Copyright©2018 NTT corp. All Rights Reserved.
public interface MongoRepository<T,ID> extends
PagingAndSortingRepository<T,ID>,
QueryByExampleExecutor<T>{
<S extends T> List<S> findAll(Example<S> example);
<S extends T> S insert(S entity);
// omitted
public interface ReactiveMongoRepository<T,ID> extends
ReactiveSortingRepository<T,ID>,
ReactiveQueryByExampleExecutor<T>{
<S extends T> Flux<S> findAll(Example<S> example);
<S extends T> Mono<S> insert(S entity);
// omitted
- 23. Copyright©2018 NTT corp. All Rights Reserved.
public class MongoTemplate implements MongoOperations,
ApplicationContextAware,
IndexOperationsProvider{
public <T> List<T> findAll(Class<T> entityClass) {
// omitted
public class ReactiveMongoTemplate implements
ReactiveMongoOperations,
ApplicationContextAware{
public <T> Flux<T> findAll(Class<T> entityClass) {
// omitted
- 24. Copyright©2018 NTT corp. All Rights Reserved.
public interface RxJava2CrudRepository<T,ID> extends
Repository<T,ID> {
<S extends T> Single<S> save(S entity);
<S extends T> Flowable<S> saveAll(Iterable<S> entities);
Maybe<T> findById(ID id);
// omitted
- 26. Copyright©2018 NTT corp. All Rights Reserved.
public interface MyReactiveRepository extends
ReactiveCrudRepository<Foo,String>{
@Tailable
public Flux<Foo> findWithTailableCursorBy();
}
@GetMapping(value=”foo", produces="text/event-stream")
public Flux<Foo> getFoo(){
return repository.findWithTailableCursorBy();
}
+
- 27. Copyright©2018 NTT corp. All Rights Reserved.
+
@Autowired
ReactiveMongoTemplate template;
// omitted
@GetMapping(value="foo", produces="text/event-stream")
public Flux<Foo> getFoo(){
return template.tail(
new BasicQuery(new Document()),
Foo.class);
}
- 30. Copyright©2018 NTT corp. All Rights Reserved.
• . . . 02
• 1 3 J OR Wb
D @ 0 1 3 1 3 a
• D 1 3 M
• D @ 2 1 3 1 3 a
• ,2.1 2 . 3 3 2 2 . 3 2 2 2 2 . 3 a
E
.
. . 2 0 :
- 31. Copyright©2018 NTT corp. All Rights Reserved.
.
0 . :
public class LoggersEndpoint
extends AbstractEndpoint<Map<String,Object>> {
@Override
public Map<String,Object> invoke() {
// omitted
}
public class LoggersMvcEndpoint extends EndpointMvcAdapter{
@ActuatorPostMapping("/{name:.*}")
@ResponseBody
@HypermediaDisabled
public Object set(@PathVariableString name,
@RequestBodyMap<String,String> configuration) {
// omitted
}
2 1
- 32. Copyright©2018 NTT corp. All Rights Reserved.
2 0.
:A A EG
@Endpoint(id="loggers")
public class LoggersEndpoint {
@ReadOperation
public Map<String,Object> loggers() {
// omitted
}
@WriteOperation
public void configureLogLevel(@Selector String name,
@NullableLogLevel configuredLevel) {
// omitted
}
B :
B :
- 35. Copyright©2018 NTT corp. All Rights Reserved.
+ +
BE
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>
management.endpoints.web.expose=health,info,prometheus
+ E
- 37. Copyright©2018 NTT corp. All Rights Reserved.
+
scrape_configs:
- job_name: 'spring-boot2'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['localhost:8080']
- 42. Copyright©2018 NTT corp. All Rights Reserved.
• 2 0
• uz N S O 0 2 nrRyil
• 5 5.
• 50 0 2 5 5 5, 5 5 0 2 nrR
l O e
• 225
• 4502. , 50 Rp nr
• 02 5
• he nr
5 5.
4502. , 50 R a
u g Rt s A C
4502. , 50 h h c N nrvo
- 43. Copyright©2018 NTT corp. All Rights Reserved.
. 0
0 A 5 .C
R W l
S W
P l
)A D3 1 B
0 A 5 1 B
2 4S l
/ 5 0 A 5 )
/ 5 0 A 5
/ 5 0 A 5
( .)A . 5
hci IOa
(
e
d
b
(
hciI
- 44. Copyright©2018 NTT corp. All Rights Reserved.
. 0
1 C B / B
e c
D
y
bd
D B I5D 2 B B
1 C B 2 B B
4 a
0B D D 1 C B
0B D D 1 C B
0B D D 1 C B
( S / D /A .- DRT
sv w D Wk
(
uz h
uzgn
l
(
sv w uz
T Rt PO SoiW
2AB : 2 B D ( r p )
DDAC) C C 5B D 5 5. 5DC 5 CAB : C B D (B A BD
- 45. Copyright©2018 NTT corp. All Rights Reserved.
<dependencies>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-jose</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
- 46. Copyright©2018 NTT corp. All Rights Reserved.
, , , IF
spring.security.oauth2.client:
registration:
facebook:
client-secret: aaaabbbbbccccdddd111122223333
client-id: xxxxxxxxxxxxxxxxx
• , / , / IF
• O C G D IF H
- 47. Copyright©2018 NTT corp. All Rights Reserved.
spring.security.oauth2.client:
registration:
XXX:
client-secret: abcdefg1234567abcdefg1234567
client-id: xxxxyyyyxxxxyyyy
redirect-uri-template: "{baseUrl}/login/oauth2/code/XXX"
client-name: XXX
client-authentication-method: post
authorization-grant-type: authorization_code
scope:
openid
profile
provider:
XXX:
authorization-uri:https://…
token-uri:https://…
user-info-uri:https://…
jwk-set-uri:https://…
- 50. Copyright©2018 NTT corp. All Rights Reserved.
( ( ( )
public interface CrudRepository<T,ID extends Serializable>
extends Repository<T,ID>{
T findOne(ID id);
Iterable<T> findAll();
Iterable<T> findAll(Iterable<ID> ids);
boolean exists(ID id);
public interface CrudRepository<T,ID> extends Repository<T,ID>{
Optional<T> findById(ID id);
Iterable<T> findAll();
Iterable<T> findAllById(Iterable<ID> ids);
boolean existsById(ID id);
(
(
- 51. Copyright©2018 NTT corp. All Rights Reserved.
( ( ( ( )
public interface CrudRepository<T,ID extends Serializable>
extends Repository<T,ID>{
<S extends T> S save(S entity);
<S extends T> Iterable<S> save(Iterable<S> entities);
public interface CrudRepository<T,ID> extends Repository<T,ID>{
<S extends T> S save(S entity);
<S extends T> Iterable<S> saveAll(Iterable<S> entities);
(
(
- 52. Copyright©2018 NTT corp. All Rights Reserved.
( ( ( )
public interface CrudRepository<T,ID extends Serializable>
extends Repository<T,ID>{
void delete(ID id);
void delete(T entity);
void delete(Iterable<? extends T> entities);
void deleteAll();
public interface CrudRepository<T,ID> extends Repository<T,ID>{
void deleteById(ID id);
void delete(T entity);
void deleteAll(Iterable<? extends T> entities);
void deleteAll();
(
(
- 53. Copyright©2018 NTT corp. All Rights Reserved.
public interface Custom{
// omitted
}
public class FooRepositoryImpl implements Custom{
// omitted
}
public interface FooRepository extends Custom,
CrudRepository<Foo,String>{
}
:
e a C D C SK
a C d
g Da R I R SK
g eD d
eD
Da C
- 54. Copyright©2018 NTT corp. All Rights Reserved.
public interface Custom{
// omitted
}
public class CustomImpl implements Custom{
// omitted
}
public interface FooRepository extends Custom,
CrudRepository<Foo,String>{
}
:
e a C D C SK
a C d
g Da R I R SK
e eD d
eD
Da C
- 55. Copyright©2018 NTT corp. All Rights Reserved.
public interface Custom{
// omitted
}
public class CustomImpl implements Custom{
// omitted
}
public interface FooRepository extends Custom, Custom2,
CrudRepository<Foo,String>{
}
:
i d D I R D K
d D g
d S S K
i i g
i
Ca
e d D
- 58. Copyright©2018 NTT corp. All Rights Reserved.
0 . 0
@Bean
public FlatFileItemReader<Foo> reader(Resource resource)
throws Exception{
FlatFileItemReader<Foo> reader = new FlatFileItemReader<>();
reader.setName(“fooReader”);
reader.setResource(resource);
BeanWrapperFieldSetMapper<Foo>fieldSetMapper=
new BeanWrapperFieldSetMapper<>();
fieldSetMapper.setTargetType(Foo.class);
fieldSetMapper.afterPropertiesSet();
DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer();
tokenizer.setNames( new String[] {“first”, “second”, “third”});
tokenizer.afterPropertiesSet();
DefaultLineMapper lineMapper = new DefaultLineMapper();
lineMapper.setLineTokenizer(tokenizer);
lineMapper.setFieldSetMapper(fieldSetMapper);
reader.setLineMapper(lineMapper);
return reader;
}
4 3
- 59. Copyright©2018 NTT corp. All Rights Reserved.
. 0 4
@Bean
public FlatFileItemReader<Foo> reader(Resource resource) {
return new FlatFileItemReaderBuilder<Foo>()
.name(“fooReader”)
.resource(resource)
.delimited()
.names(new String[]{“first”, “second”, “third”})
.targetType(Foo.class)
.build();
}