Spring配置文件模板
模板:
<?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-4.0.xsd">
<bean id="moocAppctx" class="imooc_spring.test.aware.MoocApplicationContext"
init-method="hhhh">
</bean>
</beans>
更全面的一个模板,20170327添加,
<?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"
xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
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-4.0.xsd">
<bean id="moocAppctx" class="imooc_spring.test.aware.MoocApplicationContext"
init-method="hhhh">
</bean> <!-- 引入db.properties -->
<context:property-placeholder location="classpath:db.properties" /> <!-- 配置C3P0数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="jdbcUrl" value="${jdbc.url}"></property>
<property name="driverClass" value="${jdbc.driverName}"></property>
<property name="user" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.pwd}"></property>
</bean> <!-- 配置 Spring 的 org.springframework.jdbc.core.JdbcTemplate -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean> <bean id="moocBeanNameAware" class="imooc_spring.test.aware.MoocBeanNameAware"></bean> <!-- 测试 SpEL: 可以为属性进行动态的赋值(了解) -->
<bean id="girl" class="com.helloworld.User">
<property name="userName" value="周迅"></property>
</bean> <!-- <bean id="boy" class="com.helloworld.User" init-method="init" destroy-method="destroy">
<property name="userName" value="高胜远"></property> <property name="wifeName"
value="#{girl.userName}"></property> </bean> --> <bean id="girl2" class="com.helloworld.User2">
<property name="userName" value="Talor Swift"></property>
</bean> <!-- autowired测试,自动装配测试 -->
<bean id="people" class="test.spring.autowired.Person" scope="prototype"
autowire="byName">
<property name="name" value="小明"></property>
<!-- <property name="cat" ref="cat222"></property> -->
<!-- <property name="cat" ref="cat1"></property> -->
</bean> <bean id="cat" class="test.spring.autowired.Cat" scope="prototype">
<property name="name" value="波斯猫"></property>
</bean>
<!-- <bean id="cat222" class="test.spring.autowired.Cat"> <property name="name"
value="我是小喵喵"></property> </bean> --> <bean id="people2" class="test.spring.autowired.Person" scope="prototype"
autowire="byName">
<property name="name" value="小明"></property>
<property name="cat" ref="cat222"></property>
</bean> <bean id="cat222" class="test.spring.autowired.Cat" scope="prototype">
<property name="name" value="波斯猫"></property>
</bean> <!--context:component-scan 指定 扫描的包 -->
<!--可以通过 resource-pattern 指定扫描的资源, resource-pattern="myrepository/*.class"
的含义: 只扫描 base-package 对应包下的 目录为 myrepository 的所有java Bean -->
<!-- <context:component-scan base-package="imooc_spring.test.anotation"
resource-pattern="myrepository/*.class"></context:component-scan> --> <!-- context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"
子节点指定排除哪些注解 context:include-filter type="annotation" 需要结合context:component-scan
标签的 use-default-filters="false"来使用 context:exclude-filter type="assignable"
这个expression指的是自己写的类,意思排除哪些类 expression="imooc_spring.test.anotation.TestObj" -->
<context:component-scan base-package="imooc_spring.test.anotation">
<!-- <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"
/> --> <!-- <context:exclude-filter type="assignable" expression="imooc_spring.test.anotation.TestObj"
/> --> </context:component-scan>
<context:component-scan base-package="com.aop"></context:component-scan> <!-- aop测试,需要引入aop命名空间 -->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy> <!-- aop annotationType, --> <!-- 切点的bean -->
<bean class="com.aop.xmltype.CalculatorImplxml" id="calImplxml"></bean>
<!-- 切面的bean -->
<bean class="com.aop.xmltype.MyAspectxml" id="myaspxml"></bean> <bean class="com.aop.xmltype.Diary" id="myDiary"></bean>
<!-- aop xmlType,用xml的形式配置AOP前置通知 -->
<aop:config>
<!--aop:pointcut 其实放在这儿也可以 -->
<!-- <aop:pointcut expression="execution (* com.aop.xmltype.CalculatorImplxml.*(..))"
id="pointcut1" /> --> <!-- 配置切面和通知 ,aop:aspect标签需要通过ref指定配置好的bean,id随便配置或者不配置,id的值可以随意起 -->
<aop:aspect id="myaspxml" ref="myaspxml" order="2">
<!-- 配置切点,即 要被记日记的对象, aop:pointcut 放在这儿也可以 ,切点不需要根对应的bean相关联,
只要expression指定的方法所在的类被Spring扫描得到就行,即只要所在的类配置了bean就可以 -->
<aop:pointcut expression="execution (* com.aop.xmltype.CalculatorImplxml.*(..))"
id="pointcut1" />
<!-- 切面里的具体的用于记录的方法就是一个通知,需要用通过pointcut-ref来指定具体的切点, -->
<aop:before method="logBefore" pointcut-ref="pointcut1" />
<aop:after method="logAfter" pointcut-ref="pointcut1" />
</aop:aspect> <aop:aspect ref="myDiary" order="3">
<!-- execution (* com.aop.*.*.*(..)) 包含了 com.aop.xmltype.CalculatorImplxml.*(..)) 的这种情况 -->
<!-- <aop:pointcut expression="execution (* com.aop.*.*.*(..))" id="allPointcut"/> -->
<aop:pointcut expression="execution (* com.aop.xmltype.CalculatorImplxml.*(..))" id="allPointcut"/>
<aop:before method="myEnd" pointcut-ref="allPointcut"/>
</aop:aspect> </aop:config> </beans>
所在项目:
Spring配置文件模板的更多相关文章
- 关于spring配置文件的头部编写
//普通spring配置文件模板1 <?xml version="1.0" encoding="UTF-8" ?> <beans xmlns: ...
- ssh框架中spring整合hibernate的配置文件模板(带详细注释)
applicationContext.xml的配置文件模板 <?xml version="1.0" encoding="UTF-8"?> <b ...
- 你不知道的Spring配置文件
Spring配置文件是用于指导Spring工厂进行Bean生产.依赖关系注入(装配)及Bean实例分发的"图纸".Java EE程序员必须学会并灵活应用这份"图纸&quo ...
- Spring配置文件详解
转自: http://book.51cto.com/art/201004/193743.htm 此处详细的为我们讲解了spring2.5的实现原理,感觉非常有用 spring配置文件是用于指导Sp ...
- spring配置文件详解--真的蛮详细
spring配置文件详解--真的蛮详细 转自: http://book.51cto.com/art/201004/193743.htm 此处详细的为我们讲解了spring2.5的实现原理,感觉非常 ...
- Spring 配置文件详解 (以2.5为例)
转载自:http://blog.csdn.net/zzjjiandan/article/details/22922847 Spring配置文件是用于指导Spring工厂进行Bean生 ...
- JdbcTemplae使用入门&&Spring三种连接池配置&&Spring配置文件引用外部properties文件
JdbcTemplate的使用 Spring为了各种支持的持久化技术,都提供了简单操作的模版和回调. JdbcTemplate 简化 JDBC 操作HibernateTemplate 简化 Hiber ...
- J2EE进阶(四)Spring配置文件详解
J2EE进阶(四)Spring配置文件详解 前言 Spring配置文件是用于指导Spring工厂进行Bean生产.依赖关系注入(装配)及Bean实例分发的"图纸".Java EE程 ...
- spring配置文件详解以及beans:beans标签
第一行的意思就是你这个文件的默认schema为security,所以你的beans定义就需要加上前缀beans 一般的定义文件默认都是beans: 下面是spring配置文件的详解: 转自:http: ...
随机推荐
- Qt程序打包成exe可执行文件图文教程(图文并茂,且用到了filepack)
很多Qt爱好者想发布自己的Qt软件,但却发现在其他没有安装Qt SDK的机器上无法运行,这就是本文想要说明的问题.现在网上大部分软件都要发布自己开发的应用程序,都会打包到exe文件中,待安装完exe文 ...
- 深入剖析PE文件
不赖猴的笔记,转载请注明出处. 深入剖析PE文件 PE文件是Win32的原生文件格式.每一个Win32可执行文件都遵循PE文件格式.对PE文件格式的了解可以加深你对Win32系统的深入理解. 一. ...
- uva 719 Glass Beads(后缀自动机)
[题目链接] https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=524&am ...
- 使用vi编辑binary文件
原理:使用xxd将当前文件转成hex格式,编辑,然后再转回去 /usr/bin/xxd xxd - make a hexdump or do the reverse 例子: 用binary模式启动vi ...
- 导出csv文件代码示例
//当数据量达到一定级别后(大概60000以上),excel会溢出,不能全部显示,而新版的csv好像不会出现这个问题.为什么用好像,我也是听别人说,暂时没有去验证. <?php $sql = & ...
- tree(简单并差集)
tree Accepts: 156 Submissions: 807 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65 ...
- Android 自己主动化測试之------ Monkey工具
尽管 一般公司都有专门的測试人员,可是有时候 免不了 我们既要去开发产品,也要去測试产品,測试产品.有些机械化的 点界面的操作,谷歌已经给我们提供了工具.Monkey, 猴子測试. 什么是Monkey ...
- 使用LAMP创建基于wordpress的个从博客站点
參考: http://blog.csdn.net/ck_boss/article/details/27866117 一.mysql配置 1.安装mysql yum install mysql-serv ...
- eclipse自动生成的appcompat_v7出错
用eclipse新建Android工程时,自动生成的appcompat_v7出错,有个红色交叉,而且新建的Android工程有一个红色感叹号. 这时你去看看你新建的Android工程是不是没有生成R文 ...
- JavaSE学习总结第26天_网络编程
26.01 网络编程概述 网络编程:就是用来实现网络互连的不同计算机上运行的程序间可以进行数据交换. 26.02 网络模型概述和图解 计算机网络之间以何种规则进行通信,就是网络模型研究问题. ...