フレームワーク: 春 3。
Bean のメッセージ ソース injectend が常に NULL になる理由が本当にわかりません。
スニペットは次のとおりです。
のservlet.xml
<context:annotation-config />
<context:component-scan base-package="com.myproject.controllers" />
<mvc:annotation-driven />
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="/WEB-INF/messages/messages" />
<property name="cacheSeconds" value="0" />
</bean>
messageSource が注入されるクラス
import com.myproject.controllers.forms.RegistrationForm;
@Component
public class RegistrationFormValidator implements Validator {
@Autowired
@Qualifier("messageSource")
private MessageSource messageSource;
//other stuff here...
}
ここにコントローラーがあります
@Controller
@SessionAttributes("userSearchForm")
public class UsersController extends PaginationController<ProfiledUser>{
@InitBinder(value="registrationForm")
public void initBinder(WebDataBinder binder)
{
binder.setValidator(new RegistrationFormValidator());
}
私はすでに次のことを試しました:
- 注釈を削除し、xml 構成ファイルを介してメッセージ ソースを挿入する
- MessageSourceAware インターフェースの実装
ReloadableresourceBundleMessageSource
インターフェイスを使用する代わりにa を注入しようとしていますMessageSource
すべてが壮大な失敗に終わります;-) MessageSource を適切に注入するにはどうすればよいですか?