Spring中的注解配置-注入bean
@Autowired
@Qualifier("configSearcherService")
private SearchService service; @Autowired
@Qualifier("redisService")
private RedisDelegateService redisService;
<pre name="code" class="html"><?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:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jms="http://www.springframework.org/schema/jms"
xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 由于对同一个collection的查询对象,各个对象的查询条件是不可共享的,所以需要多实例运行,scope="prototype"是多实例,不写该属性,则为共享实例 -->
<bean id="configSearcherService" class="com.solr.adjust.service.impl.SearchServiceImpl" scope="prototype"/>
<bean id="redisService" class="com.solr.adjust.service.impl.RedisDelegateService">
在applicationContext-all.xml文件中导入service配置文件
<pre name="code" class="html"><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans> <!-- getContext -->
<bean class="com.solr.adjust.entity.GlobalContext"></bean>
<import resource="applicationContext-services.xml"/>
<import resource="applicationContext-solrConfig.xml"/>
</beans>
在web.xml文件中
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- 加载applicationContext-all.xml配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext-all.xml
</param-value>
</context-param>
Spring中的注解配置-注入bean的更多相关文章
- Spring中基于注解方式管理bean
操作步骤 第一步:导入相关jar包 spring IoC的基本包 Spring支持注解的Jar包 第二步:创建Spring配置文件,ApplicationContext.xml 引入约束和开启注解扫描 ...
- Spring中@Autowired 注解的注入规则
默认根据类型,匹配不到则根据bean名字 1.声明一个service接口 public interface HelloService { void sayHello(); } 2.service接口的 ...
- Spring中三种配置Bean的方式
Spring中三种配置Bean的方式分别是: 基于XML的配置方式 基于注解的配置方式 基于Java类的配置方式 一.基于XML的配置 这个很简单,所以如何使用就略掉. 二.基于注解的配置 Sprin ...
- Spring MVC4 纯注解配置教程
阅读本文需要又一定的sping基础,最起码要成功的运行过一个SpringMvc项目. 在传统的Spring项目中,我们要写一堆的XML文件.而这些XML文件格式要求又很严格,很不便于开发.而网上所谓的 ...
- Spring中@Component注解,@Controller注解详解
在使用Spring的过程中,为了避免大量使用Bean注入的Xml配置文件,我们会采用Spring提供的自动扫描注入的方式,只需要添加几行自动注入的的配置,便可以完成 Service层,Controll ...
- Spring中@Component注解,@Controller注解详解
在使用Spring的过程中,为了避免大量使用Bean注入的Xml配置文件,我们会采用Spring提供的自动扫描注入的方式,只需要添加几行自动注入的的配置,便可以完成 Service层,Controll ...
- Spring中Value注解的使用
Spring中Value注解的使用 分类: Spring2014-08-16 17:28 2985人阅读 评论(0) 收藏 举报 有的时候我们定义了Properties文件,并且使用Spring的Pr ...
- spring+hibernate 配置多个数据源过程 以及 spring中数据源的配置方式
spring+hibernate 配置多个数据源过程 以及 spring中数据源的配置方式[部分内容转载] 2018年03月27日 18:58:41 守望dfdfdf 阅读数:62更多 个人分类: 工 ...
- Spring之基于注解的注入
对于DI使用注解,将不再需要在Spring配置文件中声明Bean实例.Spring中使用注解,需要在原有Spring运行环境基础上再做一些改变,完成以下三个步骤. (1)导入AOP的Jar包.因为注解 ...
随机推荐
- day02Java基础学习笔记
自动类型转换:容量小的类型自动转换为容量大的数据类型.数据类型按容量大小排序为: byte,short,char之间不会相互转换,他们三者在计算时首先转换为int类型 1.各种进制的表现形式和特点 二 ...
- JMeter VS LoadRunner
对比项 JMeter LoadRunner 安装 简单,下载解压即可 复杂,安装包大于1GB,安装时间较久 录制/回放模式 支持 支持 测试协议 偏少,但用户可自行拓展 较多,用户不可自行拓展 分布式 ...
- Buildroot 打包文件系统流程跟踪
/********************************************************************************* * Buildroot 打包文件系 ...
- latex的使用
要写论文了,要用到latex,总算明白了一些,在ubuntu下安装好texlive和texmaker后,在终端测试,输入命令tex: 出现上面的图说明安装好了. 在texmaker下编写tex文档,保 ...
- 每天一个linux命令(性能、优化):【转载】iostat命令
Linux系统中的 iostat是I/O statistics(输入/输出统计)的缩写,iostat工具将对系统的磁盘操作活动进行监视.它的特点是汇报磁盘活动统计情况,同时也会汇报出CPU使用情况.同 ...
- Struts2自定义标签2自定义一个按班级id查询出该班级下的学生,存放进值栈,并遍历出来。
Struts2自定义标签的流程概念: (1)需要两个类:标签类(继承相应的tag类),基本类(继承Component).标签类专门负责从客户端取得用户输入的一些属性,这个普通的jsp自定义标签一样,取 ...
- Yocto使用小技巧
1. 借助Yocto编译模块 SRC := mytest obj-m := $(SRC).o KDIR := /media/Yocto/build/tmp/work/poky-linux/linux- ...
- 适合Centos Web服务器的iptables规则
适合Centos Web服务器的iptables规则IPT="/sbin/iptables"$IPT --delete-chain$IPT --flush$IPT -P INPUT ...
- 【转】把VS的智能提示快捷键改成Eclipse的习惯
原文网址:http://programmer.blog.51cto.com/2859493/1095529 平常我一会用eclipse开发,一会又操作VS,他们直接的智能提示快捷键不一样,弄的我老是敲 ...
- phpstorm 光标设置
1.是否允许光标定位在行尾之后的任意位置Allow placement of caret after end of line 这个设置是上下换行的时候,光标可以定位在任意位置,只能通过方向键移动光标, ...