mirror of
https://github.com/OtusTeam/Spring.git
synced 2026-11-18 20:07:12 +00:00
L05-springBoot
This commit is contained in:
1 parent
0a5ccdaac8
commit
bbbb6e6e4f
4 files changed
+17
-18
No files matched your search
@@ -3,8 +3,6 @@ package ru.otus;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
//http://localhost:8080/actuator/health
|
||||
|
||||
@SpringBootApplication
|
||||
public class SpringBootDemo {
|
||||
|
||||
|
||||
+16
-1
@@ -1,17 +1,32 @@
|
||||
package ru.otus.service;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import ru.otus.configs.AppProps;
|
||||
|
||||
@Service
|
||||
public class GreetingServiceServiceImpl implements GreetingService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(GreetingServiceServiceImpl.class);
|
||||
private final MessageSource messageSource;
|
||||
private final AppProps props;
|
||||
|
||||
public GreetingServiceServiceImpl(MessageSource messageSource, AppProps props) {
|
||||
this.messageSource = messageSource;
|
||||
this.props = props;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> sayHello(String name) {
|
||||
var messageLocalized = messageSource.getMessage("hello.user", new String[]{"Ivan"}, props.getLocale());
|
||||
logger.info("Localization:{}", messageLocalized);
|
||||
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put(name, "Hello, " + name);
|
||||
map.put(name, messageLocalized);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -13,12 +13,10 @@ import ru.otus.configs.AppProps;
|
||||
public class LocalHello {
|
||||
private static final Logger logger = LoggerFactory.getLogger(LocalHello.class);
|
||||
|
||||
private final MessageSource messageSource;
|
||||
private final AppProps props;
|
||||
private final String message;
|
||||
|
||||
public LocalHello(MessageSource messageSource, AppProps props, @Value("${application.message}") String message) {
|
||||
this.messageSource = messageSource;
|
||||
public LocalHello(AppProps props, @Value("${application.message}") String message) {
|
||||
this.props = props;
|
||||
this.message = message;
|
||||
}
|
||||
@@ -26,9 +24,6 @@ public class LocalHello {
|
||||
//!!! Вообще, PostConstruct - это плохая практика !!!
|
||||
@PostConstruct
|
||||
public void printHello() {
|
||||
var messageLocalized = messageSource.getMessage("hello.user", new String[]{"Ivan"}, props.getLocale());
|
||||
logger.info("Localization:{}", messageLocalized);
|
||||
|
||||
logger.info("message from props:{}", props.getMessage());
|
||||
logger.info("message:{}", message);
|
||||
}
|
||||
|
||||
@@ -3,15 +3,6 @@ spring:
|
||||
basename: "i18n/appmessages"
|
||||
encoding: "UTF-8"
|
||||
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: info, health, beans
|
||||
|
||||
server:
|
||||
port: 8080
|
||||
|
||||
application:
|
||||
message: "Test Props msg"
|
||||
locale: ru_RU
|
||||
Reference in new issue
Block a user