在xml文件中引入带有@Configuration的Java类
在xml引入带有@Configuration的Java类,就是把这个带有@Configuration的Java类,当做一个普通的的类用<bean>标签引入:
核心代码如下:
@Configuration
public class AppConfig {
@Autowired
private DataSource dataSource;
@Bean
public AccountRepository accountRepository() {
return new JdbcAccountRepository(dataSource);
}
@Bean
public TransferService transferService() {
return new TransferService(accountRepository());
}
}
<beans>
<!-- enable processing of annotations such as @Autowired and @Configuration -->
<!--这个必须要带否则会报错-->
<context:annotation-config/>
<context:property-placeholder location="classpath:/com/acme/jdbc.properties"/>
<!--引入带有@Configuration的Java类-->
<bean class="com.acme.AppConfig"/>
<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
</beans>
在xml文件中引入带有@Configuration的Java类的更多相关文章
- 如何在web.xml文件中引入其他的xml文件(拆分web.xml)
转载自:http://www.blogjava.net/jiangjf/archive/2009/04/09/264685.html 最近在做一个Servlet+javaBean的项目,服务器用的是t ...
- 关于pom.xml文件中引入net.sf.json-lib出错问题
关于pom.xml文件中引入net.sf.json-lib出错问题 在项目中引入以下依赖时一直报错 <dependency> <groupId>net.sf.json-lib& ...
- update-help : 无法更新带有 UI 区域性 {zh-CN} 的模块“WindowsUpdateProvider”帮助: 在 HelpInfo XML 文件中检索不到 UI 区域性 zh-CN
环境 OS: Windows10 企业版 LTSC x64 CPU: Intel i5-7500 CPU 3.4GHz PowerShell:5.1.17763.503 描述 更新powershell ...
- Silverlight实用窍门系列:2.Silverlight动态加载外部XML指定地址的WebService---(动态加载外部XML文件中指定的WebService地址)【附带实例源码】
接上节所讲的,Silverlight可以加载外部的XML文件里面的内容,那么我们可不可以在外部XML里面配置一个WebService地址,并且以此加载这个地址来动态加载WebService呢?这样子就 ...
- web.xml文件中的7个错误的安全配置
web.xml文件中的7个错误的安全配置 关于Java的web.xml文件中配置认证和授权有大 量 的 文章.本文不再去重新讲解如何配置角色.保护web资源和设置不同类型的认证,让我们来看看web.x ...
- struts.xml文件中配置tiles.xml
Apache Tiles是一个JavaEE应用的页面布局框架.Tiles框架提供了一种模板机制,可以为某一类页面定义一个通用的模板,该模板定义了页面的整体布局.布局由可以复用的多个块组成,每个页面可以 ...
- 获取微信签名,并保存在xml文件中
using System; using System.Linq; using System.Text; using System.Web; using System.Web.UI; using Sys ...
- 通俗易懂,C#如何安全、高效地玩转任何种类的内存之Span的脾气秉性(二)。 异步委托 微信小程序支付证书及SSL证书使用 SqlServer无备份下误删数据恢复 把list集合的内容写入到Xml中,通过XmlDocument方式写入Xml文件中 通过XDocument方式把List写入Xml文件
通俗易懂,C#如何安全.高效地玩转任何种类的内存之Span的脾气秉性(二). 前言 读完上篇<通俗易懂,C#如何安全.高效地玩转任何种类的内存之Span的本质(一).>,相信大家对sp ...
- Spring 在xml文件中配置Bean
Spring容器是一个大工厂,负责创建.管理所有的Bean. Spring容器支持2种格式的配置文件:xml文件.properties文件,最常用的是xml文件. Bean在xml文件中的配置 < ...
随机推荐
- 原lnmp环境服务器升级为mysql+nginx+php单个docker容器构建的lnmp环境
时间:2018年2月 一.项目背景 我单位现web服务架构为lnmp环境,服务器软件.硬件升级部署难:同时开源软件日新月异,考虑到技术升级,领导决定服务器架构整体升级为容器架构,维护性.移植性强. 二 ...
- [转载]三小时学会Kubernetes:容器编排详细指南
原翻译by梁晓勇 原英文:Learn Kubernetes in Under 3 Hours: A Detailed Guide to Orchestrating Containers 我很奇怪,为什 ...
- es同步mysql同步-logstash
1.下载es https://www.elastic.co/downloads/elasticsearch 修改 config 下elasticsearch.yml ip和端口等配置 2.下载ki ...
- C#属性默认值设置
关于在MVC中view中设置默认值,可以象如下设置: 1.关于VIEWMODEL的部分 如果是C# 6.0,网上资料查到说可以 如果语法不支持,只能改回.net 2.0的写法. public cla ...
- 云计算之路-阿里云上:受够了OCS,改用ECS+Couchbase跑缓存
当今天早上在日志中发现这样的错误之后,对阿里云OCS(mecached缓存服务)的积怨倾泻而出. 2014-06-08 07:15:56,078 [ERROR] Enyim.Caching.Memca ...
- Asp.net core中Migration工具使用的交流分享
a,ul>li,em{ color:deeppink !important; } h2>a{ text-decoration:none; } ul>li{ padding:3px; ...
- 1030 Travel Plan (30 分)(最短路径 and dfs)
#include<bits/stdc++.h> using namespace std; ; const int inf=0x3f3f3f3f; int mp[N][N]; bool vi ...
- Python——数据类型之dict
字典,相当于一个列表,不过列表的索引是数字,字典的索引是数字或者字符串. 1.字典的访问 字典是典型的key-value结构,一个key对应着一个value,key就是索引,value就是要保存的值 ...
- HDU 4587 TWO NODES(割点)(2013 ACM-ICPC南京赛区全国邀请赛)
Description Suppose that G is an undirected graph, and the value of stab is defined as follows: Amon ...
- Could not resolve com.android.support.constraint:constraint-layout:1.1.3.
原文地址: http://fanjiajia.cn/2018/09/25/Android%20Studio%20Could%20not%20resolve%20com.android.support. ...