Spring Framework Learning Notes (i)

Source: Internet
Author: User

For personal notes only, make it easy for you to view them later.

How eclipse installs the spring plug-in:

Http://jingyan.baidu.com/article/1612d5005fd087e20f1eee10.html

Use Maven to add the jar packages required by spring.

Several required jar packages: core, bean, context, express. Also relies on a log packet commons-logging

In order to unify the version in the Pom.xml file, the version number is written in the properties as follows:

  <Properties>      <!--Spring Version number -        <spring.version>4.0.2.RELEASE</spring.version>        <!--mybatis Version number -        <mybatis.version>3.2.6</mybatis.version>        <!--log4j log File Management Pack version -        <slf4j.version>1.7.7</slf4j.version>        <log4j.version>1.2.17</log4j.version>  </Properties>

The complete sample pom file is:

<Projectxmlns= "http://maven.apache.org/POM/4.0.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">    <modelversion>4.0.0</modelversion>    <groupId>Com.pf.Soft</groupId>    <Artifactid>Myspringlearn</Artifactid>    <version>0.0.1-snapshot</version>    <Properties>        <!--Spring Version number -        <spring.version>4.0.2.RELEASE</spring.version>        <!--mybatis Version number -        <mybatis.version>3.2.6</mybatis.version>        <!--log4j log File Management Pack version -        <slf4j.version>1.7.7</slf4j.version>        <log4j.version>1.2.17</log4j.version>    </Properties>    <Dependencies>        <!--Spring Core Pack -        <Dependency>            <groupId>Org.springframework</groupId>            <Artifactid>Spring-core</Artifactid>            <version>${spring.version}</version>        </Dependency>        <Dependency>            <groupId>Org.springframework</groupId>            <Artifactid>Spring-beans</Artifactid>            <version>${spring.version}</version>        </Dependency>        <Dependency>            <groupId>Org.springframework</groupId>            <Artifactid>Spring-context</Artifactid>            <version>${spring.version}</version>        </Dependency>        <Dependency>            <groupId>Org.springframework</groupId>            <Artifactid>Spring-expression</Artifactid>            <version>${spring.version}</version>        </Dependency>        <!--Spring-dependent log packages -        <Dependency>            <groupId>Commons-logging</groupId>            <Artifactid>Commons-logging</Artifactid>            <version>1.1.3</version>        </Dependency>    </Dependencies></Project>

To create an entity class ProductEntity:

public class ProductEntity {/** * Product code */private string prodno;/** * Product Name */private string prodname;/** *  * @return th E prodno */public String Getprodno () {return prodno;} /** * @param prodno the prodno to set */public void Setprodno (String prodno) {this.prodno = Prodno;} /** *  * @return the ProdName */public String getprodname () {return prodname;} /** * @param prodname the prodname to set */public void Setprodname (String prodname) {this.prodname = ProdName;}

Key points:

    1. Spring's application configuration file
    2. Using Spring to get objects

The Applicationcontext.xml file is 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" xsi:schemalocation= "Http://www.springframework.org/schema/beans Http://www.springframework.org/schema/beans/spring-beans.xsd "><!--XML configuration Bean--><bean id=" Productbean "class=" com.pfSoft.beans.ProductEntity "><property name=" Prodno "value=" Toothpaste ></property> <property name= "ProdName" value= "Chopsticks" ></property></bean></beans>

Test, use spring to create the object:

ApplicationContext applicationcontext; @Beforepublic void init () {applicationcontext=new Classpathxmlapplicationcontext ("Applicationcontext.xml");} @Testpublic void Test () {try {productentity productentity= (productentity) Applicationcontext.getbean ("Productbean"); System.out.println (Productentity.getprodno ()); System.out.println (Productentity.getprodname ());} catch (Exception e) {//Todo:handle Exception}calendar Calendar = Calendar.getinstance ();}

Spring Framework Learning Notes (i)

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.