Files
Spring/2023-09/spring-05-springBoot/src/main/java/ru/otus/service/GreetingServiceServiceImpl.java
T
2023-10-15 22:59:47 +03:00

33 lines
1.0 KiB
Java

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, messageLocalized);
return map;
}
}