2011-05-27 77 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