Concise configuration of SPRING2.0 Skill series

Source: Internet
Author: User

The

      Spring2.0 has been tweaked in a number of configurations to add more flexibility and simplicity to the configuration, and this article is illustrated with two simple examples.
      Configure a data source connection pool for Apache, in the previous version of Spring 2.0, we can use a configuration similar to the following:
<?xml version= "1.0" encoding= "UTF-8" "
Ttp://www.springframework.org/dtd/spring-beans.dtd" >http://www.springframework.org /dtd/spring-beans.dtd "

  class=" Org.apache.commons.dbcp.BasicDataSource "
   Destroy-method= "Close"
  
   org.gjt.mm.mysql.driver
  
   jdbc:mysql://127.0.0.1:3306/easyjf-bbs
  root
  mypass
 

      in Spring2.0, you can define a two label as a property of its parent label, which makes the configuration file more concise, as follows:
<?xml version= " 1.0 "encoding=" UTF-8 "
Ttp://www.springframework.org/dtd/spring-beans.dtd" >http:// Www.springframework.org/dtd/spring-beans.dtd "

  class=" Org.apache.commons.dbcp.BasicDataSource "
  destroy-method=" close "
      value= "Org.gjt.mm.mysql.Driver"/>
     value= "jdbc:mysql://127.0.0.1:3306 /easyjf-bbs "/>
  
  
 

In addition, there is a very useful parser in Spring2.0, Simplepropertynamespacehandle, if the http://www.springframework.org/schema/p command space is referenced in the configuration file, You will use Simplepropertynamespacehandle to process the definition of the bean, and you can configure the set-valued method injection in a simpler way in the bean in Spring2.0, as follows:
<?xml version= "1.0" encoding= "UTF-8"?>
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 ">

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"/>

In the above configuration, using P:url can directly inject Basicdatasource URL property values, you can use the P:url-ref property to refer to another bean.
For example, Spring2.0 a previous DAO configuration:



Using the Short property method, change to the following:

Spring2.0 is more flexible and concise than the previous version configuration, and is more practical if you write the configuration manually. Of course, the old configuration has a lot of development tools such as myeclipse can be identified, do not need us to do 1.1 points of input configuration file, most of the tools for the new configuration is not recognized, therefore, according to the actual situation, as appropriate use.

Due to the limited level, the text of the deficiencies are welcome to the vast number of spring enthusiasts feel free, please "Spring fans" do not gather!

(Note: This article author, easyjf open source Team Big Gorge, reprint, please keep the author's statement.) )

trackback:http://tb.blog.csdn.net/trackback.aspx?postid=1031236

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.