Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring组件扫描未扫描jboss服务器lib目录_Spring_Jboss_Annotations_Components - Fatal编程技术网

Spring组件扫描未扫描jboss服务器lib目录

Spring组件扫描未扫描jboss服务器lib目录,spring,jboss,annotations,components,Spring,Jboss,Annotations,Components,我有一个jar文件(保存在jboss home/server/default/lib中)和一个war文件(保存在jboss home/server/default/deploy中)。jar文件包含一个servlet,用于初始化spring上下文。servlet是从war文件初始化的 问题是jar文件中的@Component(和@Service等)注释没有被扫描。它不会给出任何这样的定义异常错误。我已经在上下文xml中声明了以下内容 <context:component-scan base-

我有一个jar文件(保存在jboss home/server/default/lib中)和一个war文件(保存在jboss home/server/default/deploy中)。jar文件包含一个servlet,用于初始化spring上下文。servlet是从war文件初始化的

问题是jar文件中的@Component(和@Service等)注释没有被扫描。它不会给出任何这样的定义异常错误。我已经在上下文xml中声明了以下内容

<context:component-scan base-package="com.abc.mypack" />

在使用eclipse构建jar时,我还选择了“添加目录条目”

如果我改为基于xml的配置,它就会工作。或者,如果我将jar文件移动到war文件的WEB-INF/lib,它就可以工作了

有没有办法扫描jboss服务器lib目录中的组件


我使用的是spring 3.1和Jboss AS 6。

这些注释不会扫描库。它们扫描包,这意味着包含这些包的库必须位于类路径上

您所引用的库很可能位于不同的类加载器上


我建议将jar打包到war的WEB-INF/lib目录中。

嗨,卡尔,谢谢你的回复。正如您所提到的,当我将jar放在WEB-INF/lib目录中时,它可以工作。但这不是我想要的。我希望将jar保存在一个公共位置(如server/default/lib),所有war都可以访问它。这是可能的吗?如果库位于不同的类加载器中,Spring将看不到它并进行组件扫描。磁盘空间很便宜。另外,当不同的应用程序需要不同版本的jar时会发生什么?把罐子留在战争中。@shrinidhi:我完全同意埃里卡姆的观点。