-
Dec 10th, 2006, 11:21 AM
#1
Resource configuration problem
Hi,
I have returned to an old web app I haven't worked on for a few months, and have updated Spring from 1.2 -> 2.0, and updated Tomcat too ( I don't think this is a Tomcat problem ). The app used to run OK.
I get this error when I try to access a page in the app:
java.lang.NoSuchMethodError: org.springframework.jdbc.core.JdbcTemplate.query(L org/springframework/jdbc/core/PreparedStatementCreator;Lorg/springframework/jdbc/core/RowCallbackHandler
Ljava/util/List;
at com.starfriend.dataAccess.support.MessageJDBC.getU nreadMessagesList(MessageJDBC.java:241)
at com.starfriend.actions.NewMessageIndicator.refresh List(NewMessageIndicator.java:70)
at com.starfriend.actions.NewMessageIndicator.afterPr opertiesSet(NewMessageIndicator.java:77)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1057)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1024)
etc.
If I use the Tomcat admin page to add a datasource, then the app runs OK.
I have already defined the JNDI datasource in META-INF/context.xml:
<Context debug="3" reloadable="true">
<Logger className="org.apache.catalina.logger.FileLogger" verbosity="3" prefix="localhost_starfriend_log." suffix=".txt" timestamp="true"/>
<!-- Define a database connection pool for MYSQL -->
<Resource name="starfriendMYSQL" auth="Container" type="javax.sql.DataSource"
factory="org.apache.commons.dbcp.BasicDataSourceFa ctory"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/starfriend?autoReconnect=true"
username="userName"
password="password"
maxActive="10"
maxIdle="5"
validationQuery="SELECT 1"
testOnBorrow="true"
testWhileIdle="true"
timeBetweenEvictionRunsMillis="10000"
minEvictableIdleTimeMillis="60000"
maxWait="5000"
removeAbandoned="true"
removeAbandonedTimeout="60"
logAbandoned="true" />
</Context>
and if I edit this to deliberately make it invalid, the app doesn't work.
So it seems I need to define the datasource in the context.xml AND initiate it through the Tomcat admin page! I'm confused!
Here is the code that calls the JDBCTemplate method that throws the NoSuchMethod error:
public HashMap<String, Integer> getUnreadMessagesList() {
JdbcTemplate template = new JdbcTemplate(dataSource);
final HashMap<String, Integer> unreadMessageRecipientList = new HashMap<String, Integer>();
PreparedStatementCreator psc = new PreparedStatementCreator() {
public PreparedStatement createPreparedStatement(Connection conn)
throws SQLException {
PreparedStatement ps = conn
.prepareStatement("select toUserName, COUNT(*) as numMessages"
+ " from messages where alreadyRead = 0 and visibleToRecipient = 1"
+ " GROUP BY toUserName");
return ps;
}
};
RowCallbackHandler rch = new RowCallbackHandler() {
public void processRow(ResultSet rs) throws SQLException {
String userName = rs.getString("toUserName");
Integer numMessages = new Integer(rs.getInt("numMessages"));
unreadMessageRecipientList.put(userName, numMessages);
}
};
template.query(psc, rch);
return unreadMessageRecipientList;
}
Any advice would be most welcome,
Thanks,
John
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules