Created
January 22, 2013 22:33
-
-
Save f16z/4599296 to your computer and use it in GitHub Desktop.
Calling JRuby code from a Java bean managed by Spring.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'java' | |
| include_class 'ServiceProvider' | |
| class RubyServiceProvider < ServiceProvider | |
| def decryptJob(s) | |
| puts "DECRYPT JOB" | |
| end | |
| end | |
| RubyServiceProvider.new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface ServiceProvider { | |
| public void decryptJob(String str); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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