项目中需要使用MQ组件来接受消息,但是有的时候,在使用的时候,并不能满足spring注入的条件,无法注入。例如 在jfinal的config的afterJFinalStart中,由于jfinal集成spring,spring的注入是在controller调用之前拦截注入的,而在config中,并没有调用拦截器,所以没有注入。

那怎么办呢,只能手动注入

 <?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL">
<value>tcp://localhost:61616?wireFormat.maxInactivityDuration=0</value>
</property>
</bean>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory">
<ref bean="connectionFactory"/>
</property>
</bean>
<bean id="messagesender" class="com.supermap.sm3dad.messagequeue.CMessageSender">
<property name="jmsTemplate" ref="jmsTemplate"/>
<!-- <property name="destination" ref="destination"/> -->
</bean>
<bean id="messagereceiver" class="com.supermap.sm3dad.messagequeue.CMessageReceiver">
<property name="jmsTemplate" ref="jmsTemplate"/>
<!-- <property name="destination" ref="destination"/> -->
</bean> <!-- <bean id="config" class="com.demo.config.Config">
<property name="messagereceiver" ref="messagereceiver"/>
<property name="destination" ref="destination"/>
</bean> --> </beans>

spring注入配置

     public ActiveMQHelper(String p_brokerURL, long p_reciveTimeout) {

         ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
connectionFactory.setBrokerURL(p_brokerURL);
jmsTemplate.setConnectionFactory(connectionFactory);
jmsTemplate.setReceiveTimeout(p_reciveTimeout);
}

手动注入

在不能使用spring注入的时候,可以手动注入解决。

spring xml配置注入改为手动注入过程的更多相关文章

  1. Bean XML 配置(3)- 依赖注入配置

    Spring 系列教程 Spring 框架介绍 Spring 框架模块 Spring开发环境搭建(Eclipse) 创建一个简单的Spring应用 Spring 控制反转容器(Inversion of ...

  2. 最小化Spring XML配置

    Spring提供两种技巧,可以帮助我们减少XML的配置数量. 1.自动装配(autowiring)有助于减少甚至消除配置<property>元素和<constructor-arg&g ...

  3. 2015年12月10日 spring初级知识讲解(二)最小化Spring XML配置 注解

    序,随着Spring容器管理Bean数量增加,XML文件会越来越大,而且纯手工配置XML很繁琐,Spring和JAVA都提供了一些注解方式用以简化XML配置. 目录 一.自动装配(autowiring ...

  4. Spring XML配置里的Bean自动装配

    Spring自动装配 这段是我们之前编写的代码,代码中我们使用了P命名空间 并且使用手动装配的方式将car <bean id="address" class="cn ...

  5. [Spring]04_最小化Spring XML配置

    4.1 自动装配 Bean Spring 装配 bean 时,有时非常明确,就是需要将某个 bean 的引用装配给指定属性. 例如,若应用上下文中只有一个 javax.sql.DataSource 类 ...

  6. Spring学习笔记—最小化Spring XML配置

    自动装配(autowiring)有助于减少甚至消除配置<property>元素和<constructor-arg>元素,让Spring自动识别如何装配Bean的依赖关系. 自动 ...

  7. 最小化spring XML配置,Spring提供了4种自动装配策略。

    1.ByName自动装配:匹配属性的名字 在配置文件中的写法: <bean name="course" class="course类的全包名">&l ...

  8. 三、最小化的Spring XML配置

    Spring 提供了自动装配(自动识别如何装配Bean的依赖关系)和自动检测(检测哪些类需要被配置成Spring Bean) 1.自动装配Bean的属性 1.1四种类型得自动装配:byName.byT ...

  9. spring xml配置标签详解

    <!-- 指定类的名称 在对bean进行定义时,除了使用id属性来指定名称之外,为了提供多个名称,可以使用alias标签来指定. --> <alias name="&quo ...

随机推荐

  1. mac pro换屏指南

    https://www.ifixit.com/ 该网站提供了 换屏的详细操作步骤.

  2. 使用rsync在linux(客户端)拉取windows(服务端)数据

    windows 服务端ip:172.18.18.70 Linux客服端ip: 172.18.54.11 1.windows服务端下载cwRsync Server , 地址:https://www.ba ...

  3. 10#Windows注册表的那些事儿

    引言 用了多年的Windows系统,其实并没有对Windows系统进行过深入的了解,也正是由于Windows系统不用深入了解就可以简单上手所以才有这么多人去使用.笔者是做软件开发的,使用的基本都是Wi ...

  4. 爬虫-----爬取所有国家的首都、面积 ,并保存到txt文件中

    # -*- coding:utf-8 -*- import urllib2import lxml.htmlfrom lxml import etree def main(): file = open( ...

  5. CarbonData-1:common

    最近公司需要对CarbonData进一步应用,或许封装进产品,或许是为了解析CarbonData元数据,于是开始预研CarbonData,下面将保持每天一篇以上的阅读CarbonData源码博客,由于 ...

  6. pydemo_testMaopuSpider

    import json from multiprocessing import Pool import requests from requests.exceptions import Request ...

  7. 在Ubuntu中,vi命令编辑异常

    在Ubuntu中,进入vi命令的编辑模式,发现按方向键不能移动光标,而是会输出ABCD,以及退格键也不能正常删除字符.这是由于Ubuntu预装的是vim-tiny,而我们需要使用的是vim-full, ...

  8. org.w3c.dom.Node.getTextContent()方法编译错误-已解决

    org.w3c.dom.Node.getTextContent()方法编译错误. 在项目的Java Build Path | Order and Export选项卡中,将JRE System Libr ...

  9. SQLServer 2008以上误操作数据库恢复方法

    解决方法:       对于这类问题,主要是找回误操作之前的数据,在2008之前,有个很出名的工具Log Exploer,听说还挺好用的,这个网上大把教程,这里就不多说了.但是唯一遗憾的是,不支持20 ...

  10. python基础部分----基本数据类型

    0.文章来源:http://www.cnblogs.com/jin-xin/articles/7562422.html 1.数字 2.bool 3.str字符串 3.1.字符串的索引与切片. 索引即下 ...