Hanshunping Spring Notes First Lecture

Source: Internet
Author: User

1. What is Spring?

Struts is the web framework (php/action/actionform)

Hibernate is the ORM Framework (the framework of objects and relational mappings, in the persistence layer)

Spring is a framework for container frameworks that configure beans and maintain relationships between beans

Bean (is any object in Java javabean/service/action/data source/dao) ROC (Control inversion) di (dependency injection)

2. Develop a spring project

(1) Introduction of the spring development package, the minimum configuration Spring.jar, the package to the common jar is included, but also to write a log packet Commons-logging.jar

Create a core file for spring Applicationcontext.xml (Hibernate has core file hibernate.cfg.xml)

(2) Struts core file Struts.config.xml The file is typically in the SRC directory

(3) Configuring the bean (service/dao/daomain/action/data source) in the container file

<!--bean element's role is that when our spring framework loads, Spring automatically creates a bean object and puts it in memory equivalent to UserService userservice=new userservice () and

<bean id= "UserService" class= "Com.service.UserService" >

<property name= "Name" >//

<value> Hanshunping </value>//userservice.setname ("Hanshunping");

</property>//

<!--quoting Bybservice bean--> in UserService

<property name = "Byeservice" ref= "Bybservice" >

</bean>

<bean id= "Bybservice" class= "Com.service.BybService" >

<property name= "name" value= "Xiao Ming" >

</bean>

1. Get spring ApplicationContext Object (Container object)

ApplicationContext ac = new Classpathxmlapplicationcontext ("Applicationcontext.xml");//File is loaded

UserService US = (userservice) ac.getbean ("UserService");//Remove UserService Reference Object

Us.sayhello ();

From act represents the ApplicationContext container

Bybservice Bybservice = (bybservice) ac.getbean ("Bybservice");

Bybservice.saybye ();

3.

Spring is actually a container framework that can be configured with a variety of beans and can maintain the bean-to-bean relationship, and when we need a bean, we can Getbean ().

What is the IOC?

IOC (inverse of controll) control inversion is the transfer of the right to create objects (beans) and maintain objects (beans) from the program to the Spring container (applicationcontrol.xml)

DI: (Dependency Injection) Dependency injection: Actually DI and IOC are the same concept, and Di is more capable of representing the core of spring.

  

Hanshunping Spring Notes First Lecture

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.