struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shannon, Andrew" <>
Subject S2 Spring Bean DI to an i18n ListResourceBundle
Date Fri, 11 Jan 2008 20:33:23 GMT
I'd like to use a ListResourceBundle that pulls message information from
the database.  The pieces include (see below for code):
1.  a service that gets messages from the database.
2.  a ListResourceBundle
3.  applicationContext-struts.xml configuration to inject my service
into the resource bundle
4.  struts.xml configuration defining my i18n resource.
My new resource works fine if I hard code the key/value pairs, however,
the spring injected service is NULL.  It seems to me like the i18n
configuration is not Spring Bean aware.  Can anyone please help me
understand why the resource loader is unaware of spring or what I can do
to circumvent this?  'twould be very nice if it the DI could work in
this case as that's what makes life easy.
public class DbMessageResources extends ListResourceBundle implements
Serializable {
    private static final Log LOG =
    private MessageService messageService;
    //spring injected service
    public void setMessageService(final MessageService messageService) {
        this.messageService = messageService;
    protected Object[][] getContents() {
        LOG.debug("Loading DB Message Resources...");
        //the message is null
        List<Message> messages = messageService.getAllMessages();
        String[][] bundleContents = new
        if (messages.size() > 0) {
            for (int i = 0; i < messages.size(); i++) {
                bundleContents[i][0] = messages.get(i).getId();
                bundleContents[i][1] = messages.get(i).getMessage();
                LOG.debug("Added DB Message Resources:{" +
bundleContents[i][0] + "," + bundleContents[i][1]);
//        Works fine but I don't want to hard code these.
//        Object[][] bundleContents = {
//                {"login.userLoggedOutMsg", "Logged out"},
//                {"login.authenticationErrorMsg", "Bad Login"}};
        return bundleContents;
applicationContext-struts.xml entry:
    <bean id="dbMessageResources"
class="x.y.z.web.util.DbMessageResources" scope="singleton">
        <property name="messageService" ref="messageService"/>
struts.xml - ideally, but does not understand:
<constant name="struts.custom.i18n.resources"
struts.xml with package declaration - works, but is not Spring injected.
I believe S2 is trying to create its own instance and skipping Spring,
hence it doesn't resolve the service:
<constant name="struts.custom.i18n.resources"

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message