最近整合 spring-mvc 和 activeMq ,出现了几个异常,我把他记录下来,具体的原理分析我就不太会写了,只把详细情况和解决方案给出来,希望对各位老铁有所帮助!

问题1:缺少log4j的配置文件

异常信息:出现以下的内容时,可能就是你没有配置 log4j 了。

log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

 

解决方案:

在你的WEB-INF 目录下面,添加配置文件 log4j.properties 文件, 文件配置参考如下:

log4j.rootLogger=info, Console, err

log4j.logger.play=DEBUG

# Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.encoding=UTF-8
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern={ "time": "%d{yyyy-MM-dd HH:mm:ss}", "level": "%p", %m }%n log4j.appender.err = org.apache.log4j.DailyRollingFileAppender
log4j.appender.err.encoding=UTF-8
log4j.appender.err.File = logs/appName_error.log
log4j.appender.err.Append = True
log4j.appender.err.Threshold = ERROR
log4j.appender.err.layout = org.apache.log4j.PatternLayout
log4j.appender.err.layout.ConversionPattern = { "time": "%d{yyyy-MM-dd HH:mm:ss}", "level": "%p", %m }%n
log4j.additivity.err=false log4j.appender.info = org.apache.log4j.DailyRollingFileAppender
log4j.appender.info.encoding=UTF-8
log4j.appender.info.File = logs/appName.log
log4j.appender.info.Append = True
log4j.appender.info.Threshold = INFO
log4j.appender.info.layout = org.apache.log4j.PatternLayout
log4j.appender.info.layout.ConversionPattern = { "time": "%d{yyyy-MM-dd HH:mm:ss}", "level": "%p", %m }%n 

然后在你的 web.xml 里面添加 context-param, 代码如下

    <context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>

  

问题2:缺少对xml 文件的 schemaLocation 设置

异常内容:

applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 14; 
columnNumber: 61; cvc-complex-type.2.4.c: 通配符的匹配很全面, 但无法找到元素 'context:component-scan' 的声明。

  

解决方案:

保证自己的schemaLocation 中的元素与xmlns 一致,并版本号,如果无法确定版本号是,默认用当前版本spring的。如我的 web.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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
"> <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<!-- 配置扫描路径 -->
<context:component-scan base-package="com.spring.mvc.*">
<!-- 只扫描Service,也可以添加Repostory,但是要把Controller排除在外,Controller由spring-mvc.xml去加载 -->
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan> </beans>  

如果我将 『

http://www.springframework.org/schema/contex

http://www.springframework.org/schema/context/spring-context.xsd

注释掉,就会出现以上异常!

问题3:无法注入元素

异常内容:

org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from file 
[/Users/zeopean/IdeaProjects/springJms/target/springJms/WEB-INF/classes/spring/applicationContext-ActiveMQ.xml];
nested exception is org.springframework.beans.FatalBeanException: NamespaceHandler class
[org.apache.xbean.spring.context.v2.XBeanNamespaceHandler] for namespace
[http://activemq.apache.org/schema/core] not found;
nested exception is java.lang.ClassNotFoundException: org.apache.xbean.spring.context.v2.XBeanNamespaceHandler

  

解决方案:

这个问题困扰了我挺长时间的,后面通过谷歌,我发现原来是我的mvn 少了一个库,所以,添加上就好了。具体如下

<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-spring</artifactId>
<version>4.6</version>
</dependency>

  

问题4:无法加载ApplicationContext-ActiveMq.xml 配置文件

异常信息:

 org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'consumerService':
Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No bean named 'jmsTemplate' available

  

问题分析:

我在设置 contextConfigLocation 时,错误的写错了这样子。对!就是  classpath:spring/applicationContext.xml 少了个 * 号

,这样子是没办法加载到 ApplicationContext-ActiveMq.xml的,因为总要有地方引入,配置才能注入成功嘛!

    <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/applicationContext.xml
</param-value>
</context-param>

  

解决方案:

    <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/applicationContext*.xml
</param-value>
</context-param>

好了,就到这里,希望能大家不要踩到这些坑!

 

 

spring-mvc 集成 activeMq 常见问题 + 解决方案 (仅供参考)的更多相关文章

  1. Spring MVC集成slf4j-logback

    转自: Spring MVC集成slf4j-logback 1.  Spring MVC集成slf4j-log4j 关于slf4j和log4j的相关介绍和用法,网上有很多文章可供参考,但是关于logb ...

  2. 在Spring下集成ActiveMQ

    1.参考文献 Spring集成ActiveMQ配置 Spring JMS异步发收消息 ActiveMQ 2.环境 在前面的一篇ActiveMQ入门实例中我们实现了消息的异步传送,这篇博文将如何在spr ...

  3. 【ActiveMQ】Spring Jms集成ActiveMQ学习记录

    Spring Jms集成ActiveMQ学习记录. 引入依赖包 无论生产者还是消费者均引入这些包: <properties> <spring.version>3.0.5.REL ...

  4. spring mvc集成freemarker使用

    freemarker作为视图技术出现的比velocity早,想当年struts风靡一时,freemarker作为视图层也风光了一把.但现在velocity作为后起之秀的轻量级模板引擎,更容易得到青睐. ...

  5. spring mvc集成velocity使用

    目前流行的三大页面视图神器是:老牌大哥jsp.后起之秀freemarker和velocity.这里不详细比较这三者的优劣,总体来说,jsp是标配,但后面两个更严格的执行了视图与业务的分离,页面里是不允 ...

  6. spring boot集成activemq

    spring boot集成activemq 转自:https://blog.csdn.net/maiyikai/article/details/77199300

  7. Spring boot 集成ActiveMQ(包含双向队列实现)

    集百家之长,成一家之言.  1. 下载ActiveMQ https://mirrors.tuna.tsinghua.edu.cn/apache/activemq/5.15.9/apache-activ ...

  8. spring mvc 集成freemarker模板

    主要使用到的jar 文件:spring mvc +freemarker.jar 第一步:spring mvc 集成 freemarker <!-- 定义跳转的文件的前后缀 ,视图模式配置--&g ...

  9. jdk1.8+SpringAOP注解报java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut select错误的不知原因的解决办法[仅供参考]

    先说办法:如果Aspectweaver-1.*.*jar这三个包版本比较低, 比如1.5.0这一层次的,可以找版本高一点的包替换低版本的包,问题可以得到解决 jar包的下载地址:https://mvn ...

随机推荐

  1. tox环境安装

    ubuntu 下安装tox环境 1.apt-get install pip 2.pip install tox 3.git git clone https://github.com/openstack ...

  2. SQL 分组统计 行转列 CASE WHEN 的使用

    原文地址:http://blog.itpub.net/26451903/viewspace-733526 原文在分组统计部分  sql是有问题的     本文已将sql改正   已用红色标记  Cas ...

  3. mybatis 3.x源码深度解析与最佳实践(最完整原创)

    mybatis 3.x源码深度解析与最佳实践 1 环境准备 1.1 mybatis介绍以及框架源码的学习目标 1.2 本系列源码解析的方式 1.3 环境搭建 1.4 从Hello World开始 2 ...

  4. linux权限归属及特殊权限设置

    访问权限:读取:允许查看内容 -read写入:允许修改内容 -write可执行:允许运行和切换 -excute(以上三点rwx共同决定最终权限)归属关系:所有者:拥有此文件/目录的用户 -user所属 ...

  5. mysql常用基础操作语法(六)--对数据排序和限制结果数量的条件查询【命令行模式】

    1.使用order by对查询的结果进行排序,asc升序,desc降序: 也可以在order by后指定多个字段名和排序方式进行多级排序: 2.使用limit限制查询结果的数量: 上图中的0,代表查询 ...

  6. Visual Studio 2012 和 SVN 结合实现版本控制 AnkhSvn

    第一步: 安装VisualSVN Server Manager. 下载地址:http://www.onlinedown.net/soft/89603.htm 第二步: 安装TortoiseSVN.注意 ...

  7. <训练赛> 垃圾陷阱

    垃圾陷阱 时间限制: 1 Sec  内存限制: 128 MB提交: 78  解决: 38[提交][状态][讨论版] 题目描述 卡门--农夫约翰极其珍视的一条Holsteins奶牛--已经落了到&quo ...

  8. 畅通工程续 HDU - 1874

    某省自从实行了很多年的畅通工程计划后,终于修建了很多路.不过路多了也不好,每次要从一个城镇到另一个城镇时,都有许多种道路方案可以选择,而某些方案要比另一些方案行走的距离要短很多.这让行人很困扰. 现在 ...

  9. js数组使用JSON.stringify()和toString()的区别,JSON.parse

    JSON.stringify()中的<br><br>var arr = [1,2,3,4]; console.log(arr.toString()); // 1,2,3,4 a ...

  10. js中的0就是false,非0就是true及案例

    在处理js代码判断真假时经常会这么写. 但fun()可能得到的是数字0,这可不是表示的没有值,但是!js中的数字0就是false,非0就是true. 于是0就被无情的当做false了. 已经被这个坑过 ...