java - 如何从 spring.xml 中的外部 jar 文件引用类

标签 java configuration jar classpath

这是我在 spring.xml 中定义的 bean

<bean id="hello" class="test.Hello" />

我将类 Hello 导出到 hello.jar 并将其放置到 c:\customjar
并将该文件夹设置为 WINDOWS CLASSPATH

这是一个输出

Caused by: org.springframework.beans.factory.CannotLoadBeanClassException:
Cannot find class [test.Hello] for bean with name 'hello' defined in class path resource [spring.xml];
nested exception is java.lang.ClassNotFoundException: test.Hello

对于 xml 文件,我可以使用类似这样的方式来引用类路径

<import resource="classpath:xxxxxx.xml"/>

但这对我不起作用。


编辑

这是类源代码。

package test;

public class Hello {
    public void someMethod() {
        // do something here
    }
}

这是类路径设置。

%CLASSPATH% = XXXXXXXX;c:\customjar\hello.jar;

最佳答案

Spring 可以从不同的jar 中加载类,无需任何额外的配置。 - 对我来说,Hello 类似乎真的不在您正在运行的应用程序中。

关于java - 如何从 spring.xml 中的外部 jar 文件引用类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4322873/

相关文章:

java - 错误: Could not find or load main class at one call and no error at another call in the same script

java - 如何从 JAR 存档中读取文件?

java - 如何从 (Java) Date 对象中获取 Expiry 字段以发送到 Apple Push Notification Services?

java - 将 XSLT 函数(字符串到代码点)转换为 Java

c# - 可观察对象/动态接口(interface)?

wcf - 有关<baseAddresses>的WCF服务配置文件问题

java - 控制java调度算法

java - 如何从 Java3D 中的 IndexedGeometryArray 读取顶点坐标和三角形索引?

c# - 在 Web.Config 中添加命名空间

java - 分析项目中的所有 JAR 以获取版本和许可证信息