2011-05-27 78 views
0

我使用Spring OXM以及Struts 1,但没有使用Spring IOC集成Struts。这是因为应用程序是旧的,我只是添加了一个涉及XML绑定的模块,我无意更改应用程序的体系结构。Spring OXM不支持Struts 1

我有一个操作类调用ClasspathXmlApplicationContext用于OXM的bean注入。

这里是我的Spring上下文XML:

<?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:oxm="http://www.springframework.org/schema/oxm" 
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/oxm 
    http://www.springframework.org/schema/oxm/spring-oxm-1.5.xsd"> 

    <bean id="xmlMapper" class="com.st.mas.wmr.utils.xml.stifbinconv.XmlMapper"> 
     <property name="marshaller" ref="jaxbMarshaller" /> 
     <property name="unmarshaller" ref="jaxbMarshaller" /> 
    </bean> 
    <bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"> 
     <property name="contextPath" value="com.st.mas.wmr.utils.xml.jaxb.stifbinconv"/> 
     <property name="validating" value="true"/> 
    </bean> 
</beans> 

动作类:

public class StifBinConversionAction extends AnyDispatchAction { 
    private IProcessStifOliBinConversion svc; 

    public StifBinConversionAction() { 
     super(); 
     svc = new ProcessStifOliBinConversion(); 
    } 

服务类:

public class ProcessStifOliBinConversion 
    implements 
     IProcessStifOliBinConversion { 
    private BasicDataSource ds; 

    private IAtomStifOliBinConversion dao; 
    private ApplicationContext ctx; 
    private XmlMapper xmlMapper; 

    public ProcessStifOliBinConversion() { 
     super(); 
     ds = new BasicDataSource(); 
     //TODO consts 
     ds.setDriverClassName("oracle.jdbc.driver.OracleDriver"); 
     ds.setUrl("jdbc:oracle:thin:@sglx482:1521:wmr"); 
     ds.setUsername("wmr_online"); 
     ds.setPassword("wmr_online"); 

     dao = new AtomStifOliBinConversion(ds); 
     ctx = new ClassPathXmlApplicationContext("com/st/mas/wmr/utils/xml/stifbinconv/oxm-context.xml"); 
     xmlMapper = ctx.getBean(XmlMapper.class); 
    } 

Web应用程序提供了HTTP 500任何错误消息或堆栈跟踪。但是,如果我将ClasspathXmlApplicationContext的配置位置更改为无效,Spring将引发异常。

org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [classes/com/st/mas/wmr/utils/xml/stifbinconv/oxm-context.xml]; nested exception is java.io.FileNotFoundException: class path resource [classes/com/st/mas/wmr/utils/xml/stifbinconv/oxm-context.xml] cannot be opened because it does not exist 

似乎问题在于Spring注入。

当出现错误,但没有错误信息时,它很刺激。它让你坚持了几天。

感谢

请问

回答

1

有刺激性的,当有一个错误 但没有错误消息。它让你坚持了几天。

???有的错误信息:您的XML不能在这个位置找到:

classes/com/st/mas/wmr/utils/xml/stifbinconv/oxm-context.xml 

我说你是路过坏参数的ApplicationContext。参加4.7.1.1 Constructing ClassPathXmlApplicationContext instances - shortcuts

看看例子考虑的目录布局 看起来是这样的:

com/ 
    foo/ 
    services.xml 
    daos.xml 
    MessengerService.class 

基于ClassPathXmlApplicationContext 实例定义中的“服务 豆组成。 xml'和'daos.xml' 可以像这样实例化...

ApplicationContext ctx = new ClassPathXmlApplicationContext(
    new String[] {"services.xml", "daos.xml"}, MessengerService.class 

也许你也应该使用模式与this Constructor

ctx = new ClassPathXmlApplicationContext("oxm-context.xml", XmlMapper.class); 
+0

重读我原来的职位:Web应用程序提供了HTTP 500没有任何错误消息或堆栈跟踪。但是,如果将ClasspathXmlApplicationContext的配置位置更改为无效的,则Spring将引发异常。 – 2011-05-29 13:23:53