Hello. I'm having an issue using annotation-based xml configuration when using Spring in JRuby. Given a pojo:
and this xml configuration:Code:import org.springframework.stereotype.Component; @Component("pojoTest") public class BasicPojo {}
when I run this jruby script:Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="basicPojo" class="com.springtest.BasicPojo"/> </beans>
Code:require 'java' # require spring jars and jar containing BasicPojo omitted# context = org.springframework.context.support.ClassPathXmlApplicationContext.new("my-context.xml") puts bean.java_class.to_s
Everything works fine. However, if I don't explicitly put the bean tag in the xml and rely instead on annotation configuration:
Code:<?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:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <context:component-scan base-package="com.springtest"/> </beans>
I get a "No bean named 'basicPojo' is defined" error.
I'm confused as to how this could be, as the ClassPathXmlApplicationContext class should be unaffected by the fact that it is being executed from a JRuby script... I can run the same setup with a basic main method in Java
and it works fine. Any ideas of what I'm doing wrong? Has anyone else had success with a similar setup? I'm stumped.Code:public static void main(String[] args) { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("my-context.xml"); BasicPojo basicPojo = (BasicPojo) ctx.getBean("pojoTest"); System.out.println(basicPojo.getClass().toString()); }
Thanks in advance.


Reply With Quote
