Announcement Announcement Module
Collapse
No announcement yet.
Jruby bean init problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Jruby bean init problem

    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

    ERROR [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 bean definition is

    Code:
    <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>
    The interface is

    Code:
    package com.emeter.e3.dao.ami;
    
    public interface ITouBinDAO
    {
        List<TouBin> findBySdp(String sdpUdcId, Date startDate, Date endDate, TimeZone premiseTimeZone) throws DAOException;
    }
    and finally the ruby code is

    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!!
    Last edited by marstein; Sep 12th, 2010, 08:40 PM. Reason: added beans XML tag info
Working...
X