Skip to content

Instantly share code, notes, and snippets.

@f16z
Created January 22, 2013 22:33
Show Gist options
  • Select an option

  • Save f16z/4599296 to your computer and use it in GitHub Desktop.

Select an option

Save f16z/4599296 to your computer and use it in GitHub Desktop.
Calling JRuby code from a Java bean managed by Spring.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context" xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:jms="http://www.springframework.org/schema/jms" xmlns:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd">
<lang:jruby id="serviceProvider"
script-source="RubyServiceProvider.rb"
script-interfaces="ServiceProvider">
</lang:jruby>
</beans>
require 'java'
include_class 'ServiceProvider'
class RubyServiceProvider < ServiceProvider
def decryptJob(s)
puts "DECRYPT JOB"
end
end
RubyServiceProvider.new
public interface ServiceProvider {
public void decryptJob(String str);
}
package testing;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestJRubyIntegration {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("jruby-applicationContext.xml");
ServiceProvider sp = (ServiceProvider) context.getBean("serviceProvider");
}
}
@f16z
Copy link
Author

f16z commented Jan 22, 2013

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scriptFactory.serviceProvider': Resolution of declared constructors on bean Class [org.springframework.scripting.jruby.JRubyScriptFactory] from ClassLoader [sun.misc.Launcher$AppClassLoader@6c5bdfae] failed; nested exception is java.lang.NoClassDefFoundError: org/jruby/exceptions/JumpException

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment