spring bean中的properties元素内的ref和value的区别;* 和 ** 的区别

spring bean中的properties元素内的ref和value的区别

至于使用哪个是依据你所用的属性类型决定的。

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="configLocation" value="classpath:mybatis.xml"/>
</bean>
  • ref:引用的这个对象(可引用其他的bean对象)
  • spring管理mybatis的单个mapper,用的是ref
      spring容器会在引用后进行验证,验证当前的xml是否存在引用的bean

ref="dataSource"就是引用dataSource的bean

  • value:引用这个对象名字的字符串;直接设置一个值(赋一些简单类型的值)
  • spring 批量扫描mybatis的mapper,使用value
      spring会在容器启动,实例化bean时进行验证

* 和 ** 的区别

 <aop:config>
    <aop:pointcut id="myPointcut" expression="execution(* cn.itcast.mybatis.service.*.*(..))" />
    <!--将定义好的事务处理策略应用到上述的切入点 -->
    <aop:advisor advice-ref="txAdvice" pointcut-ref="myPointcut" />
</aop:config>
  • pointcut元素定义一个切入点,execution中的第一个 * 号用以匹配方法的返回类型,
    这里 * 号表明匹配所有返回类型。
  • com.abc.dao..(..)表明匹配cn.itcast.mybatis.service包下的所有类的所有的
    方法

原文地址:https://www.cnblogs.com/zly123/p/10440515.html

时间: 2024-08-13 02:23:07

spring bean中的properties元素内的ref和value的区别;* 和 ** 的区别的相关文章

Spring bean中的properties元素内的name 和 ref都代表什么意思啊?

<bean id="userAction" class="com.neusoft.gmsbs.gms.user.action.UserAction" scope="prototype"> <property name="userBO" ref="userBO" /> </bean> Spring bean中的properties元素内的name 和 ref都代表什么意思啊

spring bean属性及子元素使用总结

spring bean属性及子元素使用总结 2016-08-03 00:00 97人阅读 评论(0) 收藏 举报  分类: Spring&SpringMVC(17)  版权声明:本文为博主原创文章,未经博主允许不得转载. spring框架中主要有四种标签bean.alias.import.beans,其中bean标签是其他标签的基础,此文主要对bean标签的属性及其子元素进行讨论,废话不多,请往下看. 一.bean标签的属性 1)scope:用来配置spring bean的作用域 2)singl

Spring Bean 中的线程安全

在使用Spring框架时,很多时候不知道或者忽视了多线程的问题.因为写程序时,或做单元测试时,很难有机会碰到多线程的问题,因为没有那么容易模拟多线程测试的环境.但如果不去考虑潜在的漏洞,它就会变成程序的隐形杀手,在你不知道的时候爆发.而且,通常是程序交付使用时,在生产环境下触发,会是很麻烦的事. 那么Spring Bean在大多数情况下,对象实例(Object)和方法是否线程安全呢? 这就要看如何定义Bean的生命管理和范围(Scope)了,就大多数情况而言,如果不特别注意并采取方法,Sprin

Spring使用注解读取properties文件内的参数

1. 在spring的配置文件中,配置好需要读取的properties文件 <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> <

Spring MVC 中使用properties文件

首先要搭建Spring mvc的环境,然后开始properties文件里的配置: 第一步:在springcontext中注入properties,具体路径自己调整 <bean id="config" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="locations"> <list>

spring配置中,properties文件以及xml文件配置问题

spring方便我们的项目快速搭建,功能强大,自然也会是体系复杂! 这里说下配置文件properties管理的问题. 一些不涉及到代码逻辑,仅仅只是配置数据,可以放在xxxx.properties文件里面,项目功能复杂的时候,往往properties文件很多,这时,就比较容易让人困惑,有些properties的文件内容总是加载不起来,应用启动时,就不断爆出错误,说某某参数加载失败,这个是什么原因呢? 其实,这个是spring配置的时候,org.springframework.beans.fact

Spring bean中id和name的区别

最近在开发项目的时候发现spring的BeanFactory创建bean的时候有时候有2种不同的配置,即<bean id="test" class="com.TestImpl">与<bean name="test" class="com.TestImpl">,下面一起分析一下这2种配置的区别: 1.命名规范.id属性命名必须满足xml命名规范,而name属性命名可以不用遵守.不论是id属性还是name属

spring bean 读取外部properties文件

方法一:利用org.springframework.beans.factory.config.PropertyPlaceholderConfigurer <bean id="propertyConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> &l

spring bean中构造函数,afterPropertiesSet和init-method的执行顺序

http://blog.csdn.net/super_ccc/article/details/50728529 1.xml文件 [html] view plain copy print? <bean id="aaa" class="com.dingwang.Test.Aaa" init-method="init"> <constructor-arg name="name" value="ddd&qu