gpt4 book ai didi

java - 可执行 jar 文件中的 BeanDefinitionParsingException

转载 作者:行者123 更新时间:2023-12-01 15:28:35 24 4
gpt4 key购买 nike

我有以下代码:

//preparing DAO objects
FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext("test-context.xml");
surveyDao = (SurveyDao)context.getBean("surveyDao");
recordDao = (RecordDao)context.getBean("recordDao");
//creating GUI
createWindow();

问题是它在 Eclipse 中完美运行,但是当我将其导出到可执行 jar 时,它崩溃并显示以下内容

org.springframework.beans.factory.parsing.BeanDefinitionParsingException unable to locate Spring NameSpaceHandler for XML schema namespace [http://www.springframework.org/schema/tx] Offending resource: file test-context.xml

test-context.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"
default-lazy-init="true"
default-autowire="byName">

<context:annotation-config/>

<!-- <bean id="applicationContextProvider" class="org.openforis.collect.context.ApplicationContextAwareImpl" /> -->

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="file:${user.dir}/dev.properties"/>
</bean>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="${collect.devdb.url}"/>
<property name="username" value="${collect.devdb.username}" />
<property name="password" value="${collect.devdb.password}" />
</bean>

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>



<bean id="surveyDao" class="org.openforis.collect.persistence.SurveyDao" init-method="init">
<property name="dataSource" ref="dataSource"/>
</bean>

<bean id="logoDao" class="org.openforis.collect.persistence.LogoDao">
<property name="dataSource" ref="dataSource"/>
</bean>

<bean id="recordDao" class="org.openforis.collect.persistence.RecordDao">
<property name="dataSource" ref="dataSource"/>
</bean>

<bean id="taxonomyDao" class="org.openforis.collect.persistence.TaxonomyDao">
<property name="dataSource" ref="dataSource"/>
</bean>

<bean id="taxonDao" class="org.openforis.collect.persistence.TaxonDao">
<property name="dataSource" ref="dataSource"/>
</bean>

<bean id="dynamicTableDao" class="org.openforis.collect.persistence.DynamicTableDao">
<property name="dataSource" ref="dataSource"/>
</bean>

<bean id="myTest" class="com.arbonaut.collcomm.main.MyTest" init-method="init" />



<!-- Managers -->
<bean id="recordManager" class="org.openforis.collect.manager.RecordManager" init-method="init" />
<bean id="surveyManager" class="org.openforis.collect.manager.SurveyManager" init-method="init" />

<!-- Expression Factory -->
<bean id="expressionFactory" class="org.openforis.idm.model.expression.ExpressionFactory" />
<bean id="validator" class="org.openforis.idm.metamodel.validation.Validator" />
<bean id="externalCodeListProvider" class="org.openforis.collect.persistence.DatabaseExternalCodeListProvider" />

<bean id="taxonVernacularNameDao" class="org.openforis.collect.persistence.TaxonVernacularNameDao">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- enables interpretation of the @Transactional annotations for declarative transaction management-->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
</beans>

最佳答案

您是否已将 spring-tx jar 放在类路径中/重新捆绑到可执行 jar 中?

spring-tx-3.1.0-RELEASE.jar 包含 xsd http://www.springframework.org/schema/tx/spring-tx-3.1.xsd :

/org/springframework/transaction/config/spring-tx-3.1.xsd

关于java - 可执行 jar 文件中的 BeanDefinitionParsingException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9861220/

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