gpt4 book ai didi

java - Spring OXM 不适用于 Struts 1

转载 作者:行者123 更新时间:2023-12-01 15:50:31 25 4
gpt4 key购买 nike

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

我有一个操作类调用 ClasspathXmlApplicationContext 进行 OXM 的 bean 注入(inject)。

这是我的 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>

Action 类:

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 注入(inject)中。

当出现错误但没有错误消息时,这很烦人。它会让你被困好几天。

谢谢

最佳答案

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

??? 一条错误消息:在此位置找不到您的 XML:

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

我想说您正在向 ApplicationContext 传递错误的参数。看一下 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

也许您还应该将该模式与 this Constructor 一起使用:

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

关于java - Spring OXM 不适用于 Struts 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6149778/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com