当我尝试在@Controller类中获取消息时,一切正常,但是当我尝试时
要在@Service或@Component类中实现相同,我收到以下错误:
org.springframework.context.NoSuchMessageException:
No message found under code 'email.ativacao.title' for locale 'pt_BR'.
我的控制器:
@Controller
public class TestController {
@Autowired
TestService service;
@Autowired
TestComponent component;
@Autowired
private MessageSource message;
@RequestMapping(value = "/send",method = RequestMethod.GET)
public String go() {
String message = message.getMessage
("email.ativacao.title",null,new Locale("pt","BR"));
service.getMessage();
component.getMessage();
return "signsucess";
}
}
我的服务:
@Service
public class TestService {
@Autowired
private MessageSource message;
public void getMessage() {
//Error
String message = message.
getMessage("email.ativacao.title","BR"));
}
}
我的组件:
@Component
public class TestComponent {
@Autowired
private MessageSource message;
public void getMessage() {
//Error
String message = message.
getMessage("email.ativacao.title","BR"));
}
}
我的配置:
原文链接:https://www.f2er.com/spring/431734.html