开发者

Spring OXM doesn't work with Struts 1

I use Spring OXM as well as Struts 1 but without using integrating Struts with Spring IOC. This is because the application is an old one and I'm just adding a module that involves the XML binding and I have no intention to change the architecture of the application.

I have an action class calls ClasspathXmlApplicationContext for bean injection for the OXM.

Here is my spring context 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>

The action class:

public class StifBinConversionAction extends AnyDispatchAction {
    private IProcessStifOliBinConversion svc;

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

The service class:

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);
    }

The web application gives HTTP 500 WITHOUT any error message or stack trace. However, if I change the config location of the ClasspathXmlApplicationContext to an invalid one, Spring throws an exception.

org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [classes/com/st/mas/wmr/utils/x开发者_开发知识库ml/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

Seems that the problem is within the Spring injection.

It's irritating when there's an error but there's no error message. It makes you stuck for days.

Thanks

Will


It's irritating when there's an error but there's no error message. It makes you stuck for days.

??? There is an error message: your XML can't be found at this location:

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

I'd say you are passing bad parameters to the ApplicationContext. Take a look at the example in 4.7.1.1 Constructing ClassPathXmlApplicationContext instances - shortcuts

Consider a directory layout that looks like this:

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

A ClassPathXmlApplicationContext instance composed of the beans defined in the 'services.xml' and 'daos.xml' could be instantiated like so...

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

Perhaps you should also use that Pattern with this Constructor:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜