Spring Introductory Learning (i)

Source: Internet
Author: User

The main function of spring is control inversion and aspect-oriented programming, so let's write the first spring program to experience control inversion

The first is to load the configuration file

<?xml version= "1.0" encoding= "UTF-8"?>
-middle tier application context definition for the image database.
<beans xmlns= "Http://www.springframework.org/schema/beans"
xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xmlns:context= "Http://www.springframework.org/schema/context"
xmlns:tx= "Http://www.springframework.org/schema/tx"
xsi:schemalocation= "Http://www.springframework.org/schema/beans Http://www.springframework.org/schema/beans /spring-beans-2.5.xsd
Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd ">


Below we load the configuration file in the program

ApplicationContext ac = new Classpathxmlapplicationcontext ("Spring.xml");

Then create a new class

Package Com.service.impl;

Import Com.service.Service;

public class Servicebean implements Service {

public void Save () {
System.out.println ("Save ()");

Extract the interface of the class refactor----->extract interface

And then, in the test method, Confucius reversed

Package junit.test;

Import static org.junit.assert.*;

Import Org.junit.Test;
Import Org.springframework.context.ApplicationContext;
Import Org.springframework.context.support.ClassPathXmlApplicationContext;

Import Com.service.Service;

public class Springtest {

public void Test () {
ApplicationContext ac = new Classpathxmlapplicationcontext ("Spring.xml");
Service service = (service) Ac.getbean ("service");
Service.save ();


Spring Introductory Learning (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.