Go P tags in Spring

Source: Internet
Author: User

What is represented in the spring bean configuration file p:
<bean id= "Daotemplate" abstract= "true" lazy-init= "true"
p:sessionfactory-ref= "Sessionfactory"/>

P indicates that the attributes inside the bean are injected in the form P: Property name = Injected Object
The same effect as using the <property> tag inside the bean

Spring2.0 also has a very useful parser, simplepropertynamespacehandle, if the configuration file references http://www.springframework.org/schema/p command space, You will use Simplepropertynamespacehandle to process the bean definition, and you can configure the Set value method injection in a simpler way in the bean in Spring2.0, as follows:

< 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:p= "http://www.springframework.org/schema/p"

xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans.xsd ">

< bean id= "DataSource" class= "Org.apache.commons.dbcp.BasicDataSource" destroy-method= "Close"

P:driverclassname= "Org.gjt.mm.mysql.Driver" p:url= "Jdbc:mysql://127.0.0.1:3306/easyjf-bbs" p:username= "root" P: password= "MySQL"/>

</beans>

In the above configuration, using P:url, you can inject Basicdatasource URL property values directly, and you can use the P:url-ref property to refer to another bean.

For example, Spring2.0 a previous DAO configuration:

< bean id= "Userdao" class= "Com.test.UserDao" >

< property name= "DataSource" >< ref bean= "DataSource"/></property>

</bean>

Using the short attribute method, change to the following:

< bean id= "Userdao" class= "Com.test.UserDao" p:datasource-ref= "DataSource"/>

Go P tags in Spring

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.