spring xml配置注入改为手动注入过程
项目中需要使用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配置注入改为手动注入过程的更多相关文章
- Bean XML 配置(3)- 依赖注入配置
Spring 系列教程 Spring 框架介绍 Spring 框架模块 Spring开发环境搭建(Eclipse) 创建一个简单的Spring应用 Spring 控制反转容器(Inversion of ...
- 最小化Spring XML配置
Spring提供两种技巧,可以帮助我们减少XML的配置数量. 1.自动装配(autowiring)有助于减少甚至消除配置<property>元素和<constructor-arg&g ...
- 2015年12月10日 spring初级知识讲解(二)最小化Spring XML配置 注解
序,随着Spring容器管理Bean数量增加,XML文件会越来越大,而且纯手工配置XML很繁琐,Spring和JAVA都提供了一些注解方式用以简化XML配置. 目录 一.自动装配(autowiring ...
- Spring XML配置里的Bean自动装配
Spring自动装配 这段是我们之前编写的代码,代码中我们使用了P命名空间 并且使用手动装配的方式将car <bean id="address" class="cn ...
- [Spring]04_最小化Spring XML配置
4.1 自动装配 Bean Spring 装配 bean 时,有时非常明确,就是需要将某个 bean 的引用装配给指定属性. 例如,若应用上下文中只有一个 javax.sql.DataSource 类 ...
- Spring学习笔记—最小化Spring XML配置
自动装配(autowiring)有助于减少甚至消除配置<property>元素和<constructor-arg>元素,让Spring自动识别如何装配Bean的依赖关系. 自动 ...
- 最小化spring XML配置,Spring提供了4种自动装配策略。
1.ByName自动装配:匹配属性的名字 在配置文件中的写法: <bean name="course" class="course类的全包名">&l ...
- 三、最小化的Spring XML配置
Spring 提供了自动装配(自动识别如何装配Bean的依赖关系)和自动检测(检测哪些类需要被配置成Spring Bean) 1.自动装配Bean的属性 1.1四种类型得自动装配:byName.byT ...
- spring xml配置标签详解
<!-- 指定类的名称 在对bean进行定义时,除了使用id属性来指定名称之外,为了提供多个名称,可以使用alias标签来指定. --> <alias name="&quo ...
随机推荐
- python使用telnetlib
python使用telnetlib 1 前言 目前,本篇仅记录前段时间搜索得到的关于python使用Telnet的技术博客,由于受领新任务,未进一步验证和深入研究与应用. 参考链接: python官网 ...
- python --(链表)
链表的使用 #/usr/bin/python#-*- coding: utf-8 -*-#Function: simulate the link-list in python#__author__: ...
- mysql千万级大数据SQL查询优化30条经验
转自http://blog.163.com/zhangjie_0303/blog/static/9908270620146951355834/ 1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 w ...
- C++模板的要点
1.函数模板与普通函数的区别: 普通函数可以进行自动类型转化,而函数模板不可以. 举个例子 //函数模板 template<class T> void show(T a,T b){ cou ...
- Fiddler抓包【1】_介绍及界面概述
一. 主要抓包工具介绍与对比 1.Wireshark :通用抓包工具,抓取信息量庞大,需要过滤才能得到有用信息,只抓HTTP请求有点大财小用. 2.Firebug.HttpWatch等Web调试工 ...
- python打包
打包生成一个可执行文件(非窗口程序的) pyinstall -F example.py
- 阿里负载均衡,配置中间证书问题(在starcom申请免费DV ssl)
前提假如免费版相关证书都已经配置到位,但是微信小程序Android访问有问题,检测域名(https://www.myssl.cn/tools/check-server-cert.html)发现服务器缺 ...
- 1. centos下安装docker
CentOS Docker 安装 Docker支持以下的CentOS版本: CentOS 7 (64-bit) CentOS 6.5 (64-bit) 或更高的版本 前提条件 目前,CentOS 仅发 ...
- 【论文速读】Pan He_ICCV2017_Single Shot Text Detector With Regional Attention
Pan He_ICCV2017_Single Shot Text Detector With Regional Attention 作者和代码 caffe代码 关键词 文字检测.多方向.SSD.$$x ...
- VS 通过局域网访问调试状态下的web应用程序
1.点击vs的启动按钮 2.在任务栏找到IIS Express的图标,点击“显示所有应用程序” 3.如果只有本地localhost访问方式,点击对应应用程序的本地URL,就会显示对应的配置文件 4.点 ...