com.atguigu.spring.beans.annotation.test; Import Org.springframework.stereotype.Controller; @Controller // Identify presentation layer components Public class Usercontroller { publicvoid Test () { System.out.println (" panpan789 ");} }The above classes are built under the package com.atguigu.spring.beans.annotation.test;Spring XML configuration file: Beansannotation.xml, with the above four annotations under a Com.atguigu.spring.bean
();Usbdevice.write (data);Usbdevice.pop ();}public void Setusbdevice (USB u){Usbdevice=u;}}In modifying the configuration file Applicationcontext.xml, instantiate the bean with the following code:lazy-init= "Default" autowire= "Default" >lazy-init= "Default" autowire= "Default"p:usbdevice-ref= "Theudisk" >Finally test the class, get the injected bean, the code is as follows:public class Test {public static void Main (string[] args){ApplicationContext context=new classpathxmlapplicationcontext (
Spring relies on checking that the bean profile is used to determine that all properties of a particular type (base, collection, or object) are set. In most cases, you only need to make sure that a specific property has been set but not all properties: In this case, you need to @Required annotations, see the example below: @Required example Customer object, applicable @required in the Setperson () method to ensure that the person property is set.Packa
ClassLoader is Tomcat's WebappClassLoader, This time we find the path to the resource is an empty string. This class returns two URLs, one is ${webapps}/web-inf/classes, and the other is ${tomcat-home}/lib, strange, incredibly ${webapps }/web-inf/lib is not in the return URL, a bit magical, let's look!Public enumerationThis method is actually webappclassloader directly inherit the classload come over, Parentclassload actually find the time of the classpath of the Tomcat container is findresourc
Set-value injection is one of the many dependency injection types supported by spring and the most common one. Setter injection is used to call the setter method after instantiating the managed bean by calling the non-parametric Constructor (or the non-parametric static factory method, or the factory Bean's pipeline static factory method, to establish the dependency
Spring relies on injection (DI) in three ways, respectively:
1. Interface Injection
2. Setter Method Injection
3. Construct Method Injection
Here's how these three dependency injections are implemented in spring.
First we need the following classes:
Interface Logic.java
Interface Implementation Class Logicimpl.java
A processing class Loginaction.java
There is
Excerpt from the Spring Handbook, an example of dependency injection
The following example uses Xml-based configuration metadata for setter-based DI. A small part of a Spring XML configuration file specifies some bean definitions:
Spring uses annotations to implement IOC and Di
Annotations in a way that implements Iocdi1. IOC operation1) @Component: Used to implement IOC control inversion, attribute value is used to implement object ID definition2) @Scope: For the configuration of single case, multiple cases, request,session, etc.3) @Controller: annotations specifically for controller layers for control inversion, property value4) @Service: Annotations specifically for Service
Part V. The WebThis section of the documentation describes the spring framework's support for the presentation layer (especially the Web-based presentation layer)Spring has its own web framework--spring Web MVC, which is described in the first two chapters. The rest of the chapters are used to introduce the integration
are as follows:· Bytype assembly by type you can find the type-matching bean in the container based on the property type, if there are more than one, an exception is thrown, and if not found, the property value is null;· ByName by name the bean with the same property name can be queried in the container based on the name of the property, and if not found, the property value is null;· constructor is similar to the bytype approach, where it is applied to the constructor parameter, and throws an e
Spring Framework and MVC principlesDirectory
Spring Framework
SPRINGMVC Working principle
Resources
Back to TopSpring Framework
Spring's current framework has a jar package that can be roughly divided into 6 main modules:
Core Container
AOP and Instrumentation
Messaging
Data access/integration
Web
Test
Spring+spring mvc+hibernate Environment collocationSpring+spring Mvc+hibernate referred to as "SSH". The spring container is the core of spring, which is responsible for managing Java c
remark:
A basic understanding of spring boot has been made through the previous chapters, but spring boot is just a box that encapsulates an integrated reference and needs to be combined with a specific project to really use it.
The main record is to use spring boot to implement the integration of spring
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.