I'm putting together a proof of concept application where I'd like to
elegantly inject Spring beans on Rails controllers. I successfully got
an instance of the Spring applicationContext using
WebApplicationContextUtils and the servlet_context introduced by Chris
Nelson. I'm now defining the Rails controller in the Spring context
and trying to inject a Java bean into it.
Here's what I have so far:
----> in applicationContext.xml:
<lang:jruby id="booksController"
script-interfaces="com.digitalsanctum.jrubyprototype.jruby.BookStoreAware"
script-source="/app/controllers/books_controller.rb">
<lang:property name="bookStore" ref="bookStore"/>
</lang:jruby>
----> in books_controller.rb:
require 'java'
#include_class
'org.springframework.web.context.support.WebApplicationContextUtils'
include_class 'com.digitalsanctum.jrubyprototype.domain.logic.BookStore'
class BooksController < ApplicationController
def setBookStore(bookStore)
@@bookStore = bookStore
end
def list
# @book_pages, @books = paginate :books, :per_page => 10
logger.info("reached list")
# ctx =
WebApplicationContextUtils.getWebApplicationContext($servlet_context);
# bookStore = ctx.getBean("bookStore");
logger.info(@@bookStore)
end
...
end
----> Here's the exception:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'scriptedObject.booksController':
Instantiation of bean failed; nested exception is
org.springframework.beans.factory.BeanDefinitionStoreException:
Factory method [public java.lang.Object
org.springframework.scripting.jruby.JRubyScriptFactory.getScriptedObject(org.springframework.scripting.ScriptSource,java.lang.Class[])
throws
java.io.IOException,org.springframework.scripting.ScriptCompilationException]
threw exception; nested exception is
org.springframework.scripting.ScriptCompilationException: Could not
compile JRuby script [ServletContext resource
[/app/controllers/books_controller.rb]]: uninitialized constant
ApplicationController; nested exception is
org.jruby.exceptions.RaiseException
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:435)
at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:255)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:252)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at
org.springframework.scripting.support.ScriptFactoryPostProcessor.postProcessBeforeInstantiation(ScriptFactoryPostProcessor.java:284)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:673)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:373)
at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:255)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:252)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:303)
at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:689)
at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:358)
at
org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:244)
at
org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:187)
at
org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
at
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3764)
I realize this is a Spring exception but I'm guessing this list would
have a better idea of what's going on rather than a Spring mailing
list. Looking at the exception, it seems like Spring isn't aware of
the Rails superclass ApplicationController but I'm not sure of the
best way to handle this.
Any guidance is appreciated.
--
Thank you,
Shane Witbeck
Digital Sanctum, inc.
-----------------------------------------------------
skype: digitalsanctum
blog: http://www.digitalsanctum.com
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel