spring properties 코드에 injection하기
컨트롤러 코드
@Controller public class HomeController {
private static final Logger LOG = LoggerFactory.getLogger(HomeController.class);
//@Value("${username}")
//private String username;
@Value("#{aPropertiesFactoryBean.prop1}")
private String prop1;
@Value("#{aPropertiesFactoryBean.username}")
private String username;
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
LOG.info("Welcome home! the client locale is "+ locale.toString());
System.out.println(username);
System.out.println(prop1);
Date date = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
String formattedDate = dateFormat.format(date);
model.addAttribute("serverTime", formattedDate );
return "home";
}
설정코드
<?xml version=”1.0” encoding=”UTF-8”?>
properties파일
##FileName : beansugar.properties username=usertest url=http://192.168.0.51/