I am trying to use a scripted bean but get an error.
I am using jruby-1.0.3 and spring-2.5.6
The error message is
The bean definition isERROR [main] SingletonApplicationContextFactory.getApplicationC ontext(31) | Context
failed to initialize: Error creating bean with name 'RtouBinDAO':
BeanPostProcessor before instantiation of bean failed;
nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating
bean with name 'scriptedObject.RtouBinDAO': Invocation of init method failed; nested exception is java.lang.NoSuchMethodException: Couldn't find an init method named 'onInit' on bean with name 'scriptedObject.RtouBinDAO'
The interface isCode:<beans xmlns="http://www.springframework.org/schema/beans" .... default-init-method="onInit"> <lang:jruby id="RtouBinDAO" script-interfaces="com.emeter.e3.dao.ami.ITouBinDAO" script-source="classpath:mock_tou_bin_dao.rb"> </lang:jruby>
and finally the ruby code isCode:package com.emeter.e3.dao.ami; public interface ITouBinDAO { List<TouBin> findBySdp(String sdpUdcId, Date startDate, Date endDate, TimeZone premiseTimeZone) throws DAOException; }
Code:require 'java' include_class 'com.emeter.e3.domain.TouBin' include_class 'java.util.Date' include_class 'java.util.HashMap' include_class 'java.util.List' include_class 'java.util.TimeZone' include_class 'com.emeter.e3.dao.ami.ITouBinDAO' class MockTouBinDAO include com.emeter.e3.dao.ami.ITouBinDAO @toubinmap = HashMap.new def findBySdp sdpudcid, premisestartdatetime, premiseenddatetime, tz @toubinmap.get(sdpudcid+premiseenddatetime.getTime()+premisestartdatetime.getTime()) end def onInit puts 'Initializing mock tou bin DAO!!' end end MockTouBinDAO.new # Spring likes this
I am not sure what is wrong. This seems to follow the examples in the documentation quite nicely. Why the problem "Couldn't find an init method named 'onInit'". I added the onInit() method and this didn't solve the problem. Thanks!!


Reply With Quote
