gpt4 book ai didi

java.lang.NoClassDefFoundError : org/springframework/context/support/ClassPathXmlApplicationContext 错误

转载 作者:行者123 更新时间:2023-11-30 09:10:53 24 4
gpt4 key购买 nike

我在我的 Jar 文件中使用 Spring 从属性文件中获取属性。当我尝试从我的 RAD(eclipse) 中获取输出时。但是当我在服务器中部署我的 jar 文件时,我不断收到此错误。我是否需要包含任何其他 XML 文件?

获取应用程序上下文时发生错误。

ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

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:p="http://www.springframework.org/schema/p"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/util http://xml.westfieldgrp.com/public/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/beans http://xml.westfieldgrp.com/public/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jee http://xml.westfieldgrp.com/public/schema/jee/spring-jee-3.0.xsd" >
<bean id="applicationProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:/config/devint/nimo.properties"/>
</bean>
<bean id="nimoConfigurationBean" scope="singleton"
class="com.westfieldgrp.filenet.env.NimoConfigurationBean">
<property name="serviceUser" value="${env.user}" />
<property name="servicePass" value="${env.pass}" />
</bean>
</beans>

用 Java 调用:

public class AddEnvProperty {

public String envType(String propertyValue) {
String returnValue = "";

AddEnvProperty envProps = new AddEnvProperty();
NimoConfigurationBean nimoConfigurationBean = envProps.getConfig();

PluginLogger logger = new PluginLogger(new ResponceFilterPlugin());
logger.logDebug(this, "envType", "Getting Property Value" + propertyValue);
try {

if (propertyValue == "USER") {
returnValue = nimoConfigurationBean.getServiceUser();
} else if (propertyValue == "PASS") {
returnValue = nimoConfigurationBean.getServicePass();
}

} catch (NullPointerException ex) {
logger.logError(this, "envType", "NullPointerException:", ex);
}catch (Exception ex) {
logger.logError(this, "envType", "NullPointerException:", ex);
}
return returnValue;
}

private NimoConfigurationBean getConfig() {
ApplicationContext context =
new ClassPathXmlApplicationContext("applicationContext.xml");

NimoConfigurationBean obj = (NimoConfigurationBean) context.getBean("nimoConfigurationBean");
return obj;
}
}

NimoConfigurationBean.java 中的 getter、setter 方法

最佳答案

检查您的 pom 文件中是否有该依赖项:

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>x.x.x.RELEASE</version>
</dependency>

(x.x.x : 待修改)

如果你没有使用 maven :将 jar“spring-context-x.x.x.RELEASE.jar”检查到您的构建路径中

关于java.lang.NoClassDefFoundError : org/springframework/context/support/ClassPathXmlApplicationContext 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22331469/

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