Spring常用注解、配置整理

原创作品,出自 “晓风残月xj” 博客,欢迎转载,转载时请务必注明出处(http://blog.csdn.net/xiaofengcanyuexj)。

由于各种原因,可能存在诸多不足,欢迎斧正!

1、context:property-placeholder

加载配置信息的键值对,可以在专用的配置文件写好,然后通过该申明引入。

?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:c="http://www.springframework.org/schema/c"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:task="http://www.springframework.org/schema/task"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
   http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
   http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
	<!-- 加载所有properties文件的spring配置 -->
	<context:property-placeholder location="classpath*:*.properties" ignore-unresolvable="true" />
	
	<bean id="masterDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
		destroy-method="close">
		<property name="driverClass" value="${driver}" />
		<property name="jdbcUrl" value="${jdbcurl}" />
		<property name="user" value="${username}" />
		<property name="password" value="${password}" />
		<property name="minPoolSize" value="5" />
		<property name="maxPoolSize" value="10" />
		<property name="maxIdleTime" value="1800" />
		<property name="acquireIncrement" value="4" />
		<property name="maxStatements" value="0" />
		<property name="initialPoolSize" value="6" />
		<property name="idleConnectionTestPeriod" value="80" />
		<property name="acquireRetryAttempts" value="40" />
		<property name="breakAfterAcquireFailure" value="true" />
		<property name="testConnectionOnCheckout" value="false" />
	</bean>

 需要在location对应的目录下存在.properties文件,存在上面所需的键值对。

ttsDriver=org.postgresql.Driver
ttsJdbcurl = jdbc:postgresql://l-alibaba.tmall.com:5432/c2c_product
ttsUsername = tmall
ttsPassword = 971b862b-79a5-4562-a640-1c7b91286d11

2、import resource

加载某个目录下的资源文件

<import resource="classpath*:spring-*.xml" />


3、context:component-scan

扫描Javabean,体现spring的IOC特点

<context:component-scan base-package="com.alibaba.tmall.b2c">
	<context:exclude-filter type="annotation"
		 expression="org.springframework.stereotype.Controller" />
</context:component-scan>


4、aop:aspectj-autoproxy

加载代码中有@Aspect标签的切片,proxy-target-class属性值决定是接口的还是类的代理被创建。如果proxy-target-class 属性值被设置为true,那么类的代理将起作用,如cglib库;如果proxy-target-class属值被设置为false或者这个属性被省略,那么标准的JDK基于接口的代理。当时,如果没有对应接口,只有实现,类的代理将起作用。

<aop:aspectj-autoproxy proxy-target-class="true"/>  


  路漫漫其修远兮,很多时候感觉想法比较幼稚。首先东西比较简单,其次工作也比较忙,还好周末可以抽时间处理这个。由于相关知识积累有限,欢迎大家提意见斧正,在此表示感谢!后续版本会持续更新…



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值