将web项目作为maven项目的依赖包

一、操作步骤

1、jar中的bean被spring ioc托管

2、在spring mvc容器对应的配置文件中,设置依赖jar中得controller扫描

3、pom.xml中设置依赖项目的依赖配置

    <dependency>

<groupId>com.nfbird</groupId>

<artifactId>nfbird-bpm-restful</artifactId>

<version>1.3.0-SNAPSHOT</version>

     </dependency>

4、使用maven的jar方式打包


二、可能遇到问题 

1、问题:服务器启动报错bean找不到

nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'birdDiagramController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com、nfbird.bpm.restful.diagram.ProcessExperience] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER, lookup=)}

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529) ~[spring-beans-3.2.7.RELEASE.jar:3.2.7.RELEASE]


问题原因:
jar中的bean没有被spring ioc托管
解决办法:
添加依赖jar中spring bean ioc配置 
root-context.xml添加

<context:component-scan base-package="com.nfbird.bpm.restful">

<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>

</context:component-scan>


2、问题:访问jar中的controller报404错

问题原因:
使用maven打包,使用war和jar打的包的文件层次是不同的。
原来jar包的pom.xml文件中是按照war方式打包的,打成的jar包的文件结构是按照web的层次结构,导致无法找到相关路径下的任何类
解决办法:

将pom.xml文件的packaging设置为jar


3、问题:使用jar方式打包后,依然报404

问题原因:
用一个eclipse中打开两个web项目,依赖优先使用eclipse中的项目,而不是使用maven仓库中的。会将eclipse中的项目按照web的层次结构打成jar。
解决办法:
在eclipse中,把被依赖的web项目关闭掉。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值