Skip to content
This repository has been archived by the owner on Nov 11, 2022. It is now read-only.

NPE with Importer #8

Open
shvaber opened this issue Jan 22, 2014 · 2 comments
Open

NPE with Importer #8

shvaber opened this issue Jan 22, 2014 · 2 comments

Comments

@shvaber
Copy link

shvaber commented Jan 22, 2014

here is my config:
< bean id="messageSource" class="org.synyx.messagesource.InitializableMessageSource">
< property name="messageProvider">
< bean class="org.synyx.messagesource.jdbc.JdbcMessageProvider">
< property name="dataSource" ref="dataSource"/>
< property name="keyColumn" value="messageKey"/>
< property name="tableName" value="message"/>
< property name="basenameColumn" value="basename"/>
< property name="delimiter" value="`"/>
</ bean>
</ property>
< property name="basenames">
< list>
< value>messages</ value>
< value>application</ value>
</ list>
</ property>
< property name="returnUnresolvedCode" value="true" />
</ bean>

here is how do I call it:
public void importMessages () {
FileSystemMessageProvider filesystemMessageProvider = new FileSystemMessageProvider("webapp/WEB-INF/i18n");
JdbcMessageProvider jdbcMessageProvider = new JdbcMessageProvider();
MessageProvider source = filesystemMessageProvider;
MessageAcceptor target = jdbcMessageProvider;

    Importer importer = new Importer(source, target);

    // imports messages of all basenames from source to target
    //importer.importMessages();

    // or just import some basenames?
    Collection<String> basenames = source.getAvailableBaseNames();
    for (String basename : basenames) {
        LoggerFactory.getLogger(getClass()).info(basename);
        importer.importMessages(basename);
    }
}

An exception:
ERROR org.springframework.scheduling.support.TaskUtils$LoggingErrorHandler - Unexpected error occurred in scheduled task.
java.lang.NullPointerException
at org.synyx.messagesource.jdbc.JdbcMessageProvider.deleteMessages(JdbcMessageProvider.java:141)
at org.synyx.messagesource.jdbc.JdbcMessageProvider.setMessages(JdbcMessageProvider.java:76)
at org.synyx.messagesource.importer.Importer.importMessages(Importer.java:43)
...

As I see in log, basename has been sent to importer.
Could you please reply, if I'm missing something.

And I found small issue in doc you posted, there is
< property name="basename">
< list>
< value>messages</ value>
< value>application</ value>
</ list>
</ property>
Should be
< property name="basenameS">
< list>
< value>messages
< value>application
</ list>
</ property>
basenames - not basename.
Also is there any way to email your team or better way is to post here?

Thanks a lot for your help!

@amitsaluja
Copy link

Please initialize the data source for your jdbcmessageprovider.By calling jdbcMessageProvider.setDataSource("your dataSource");

so after
JdbcMessageProvider jdbcMessageProvider = new JdbcMessageProvider(); this line seems to be the issue.
//add following
jdbcMessageProvider.setDataSource(dataSource);

@shvaber
Copy link
Author

shvaber commented Jan 22, 2014

no, it wasn't proper solution for me due to I had to send datasource as an object, firstly get it from context.
I applied next logic:
< bean class="org.synyx.messagesource.jdbc.JdbcMessageProvider" id="jdbcMessageProvider">
< property name="dataSource" ref="dataSource"/>
< property name="keyColumn" value="messageKey"/>
< property name="tableName" value="message"/>
< property name="basenameColumn" value="basename"/>
< property name="delimiter" value="`"/>
</ bean>
< bean id="messageSource" class="org.synyx.messagesource.InitializableMessageSource">
< property name="messageProvider" ref="jdbcMessageProvider"/>
.....
< /bean>
and

@Autowired
JdbcMessageProvider jdbcMessageProvider;

in class file.

NPE is off now, thanks a lot for your great solution!
Btw, is there any way how to ask messageSource to create new message and save it when returnUnresolvedCode = true?

It will be helpfull, bcoz of database will be auto populated when message is not found.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants