spring配置

开启注解:

<context:annotation-config/>

springmvc配置注解驱动:

<mvc:annotation-driven />

配置包扫描器,扫描所有带@Service注解的类(开启注解,做了两件事):

<context:component-scan base-package="com.taotao.content.service"/>

加载配置文件:

<context:property-placeholder location="classpath:properties/db.properties" />

数据库连接池:

<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"

destroy-method="close">

<property name="url" value="${jdbc.url}" />

<property name="username" value="${jdbc.username}" />

<property name="password" value="${jdbc.password}" />

<property name="driverClassName" value="${jdbc.driver}" />

<property name="maxActive" value="10" />

<property name="minIdle" value="5" />

</bean>

让spring管理sqlsessionfactory 使用mybatis和spring整合包中的:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">

<!-- 数据库连接池 -->

<property name="dataSource" ref="dataSource" />

<!-- 加载mybatis的全局配置文件 -->

<property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml" />

</bean>

Mapper映射文件的包扫描器:

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">

<property name="basePackage" value="com.taotao.mapper" />

</bean>

事务管理器:

<bean id="transactionManager"

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

<!-- 数据源 -->

<property name="dataSource" ref="dataSource" />

</bean>

通知:

<tx:advice id="txAdvice" transaction-manager="transactionManager">

<tx:attributes>

<!-- 传播行为 -->

<tx:method name="save*" propagation="REQUIRED" />

<tx:method name="insert*" propagation="REQUIRED" />

<tx:method name="add*" propagation="REQUIRED" />

<tx:method name="create*" propagation="REQUIRED" />

<tx:method name="delete*" propagation="REQUIRED" />

<tx:method name="update*" propagation="REQUIRED" />

<tx:method name="find*" propagation="SUPPORTS" read-only="true" />

<tx:method name="select*" propagation="SUPPORTS" read-only="true" />

<tx:method name="get*" propagation="SUPPORTS" read-only="true" />

</tx:attributes>

</tx:advice>

切面:

<aop:config>

<aop:advisor advice-ref="txAdvice"

pointcut="execution(* com.taotao.content.service.*.*(..))" />

</aop:config>

spring发布dubbo服务:

提供方应用信息,用于计算依赖关系:

<dubbo:application name="taotao-content" />

<!-- 注册中心的地址 -->

<dubbo:registry protocol="zookeeper" address="192.168.119.128:2181" />

<!-- 用dubbo协议在20880端口暴露服务 -->

<dubbo:protocol name="dubbo" port="20881" />

<!-- 声明需要暴露的服务接口 -->

<dubbo:service interface="com.taotao.content.service.ContentCategoryService" ref="contentCategoryServiceImpl" timeout="300000"/>

<dubbo:service interface="com.taotao.content.service.ContentService" ref="contentServiceImpl" timeout="300000"/>

springmvc引用dubbo服务:

<dubbo:application name="taotao-portal-web"/>

<dubbo:registry protocol="zookeeper" address="192.168.119.128:2181"/>

<dubbo:reference interface="com.taotao.content.service.ContentService" id="contentService" />

springmvc视图解析器:

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="prefix" value="/WEB-INF/jsp/" />

<property name="suffix" value=".jsp" />

</bean>

redis单机版:

<bean id="jedisPool" class="redis.clients.jedis.JedisPool">

<constructor-arg name="host" value="192.168.25.128"/>

<constructor-arg name="port" value="6379"/>

</bean>

<bean id="jedisClientPool" class="com.taotao.jedis.JedisClientPool"/>

redis集群:

<bean id="jedisCluster" class="redis.clients.jedis.JedisCluster">

<constructor-arg>

<set>

<bean class="redis.clients.jedis.HostAndPort">

<constructor-arg name="host" value="192.168.25.128"/>

<constructor-arg name="port" value="7001"/>

</bean>

<bean class="redis.clients.jedis.HostAndPort">

<constructor-arg name="host" value="192.168.25.128"/>

<constructor-arg name="port" value="7002"/>

</bean>

<bean class="redis.clients.jedis.HostAndPort">

<constructor-arg name="host" value="192.168.25.128"/>

<constructor-arg name="port" value="7003"/>

</bean>

<bean class="redis.clients.jedis.HostAndPort">

<constructor-arg name="host" value="192.168.25.128"/>

<constructor-arg name="port" value="7004"/>

</bean>

<bean class="redis.clients.jedis.HostAndPort">

<constructor-arg name="host" value="192.168.25.128"/>

<constructor-arg name="port" value="7005"/>

</bean>

<bean class="redis.clients.jedis.HostAndPort">

<constructor-arg name="host" value="192.168.25.128"/>

<constructor-arg name="port" value="7006"/>

</bean>

</set>

</constructor-arg>

</bean>

<bean id="jedisClientCluster" class="com.taotao.jedis.JedisClientCluster"/>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值