inotgo.com

Download area
File name File size
lib.rar 12m
spring.rar 12m

Tool version compatibility problem
Spring Is based on IOC and AOP The structure of J2EE The framework of the system
IOC Reverse control yes Spring Basis of ,Inversion Of Control
To put it simply, create objects by former programmers themselves new Construct methods to call , It becomes a matter of Spring Create objects
DI Dependency injection Dependency Inject. In short, it is the property of the object obtained , The correlation values have been injected , Just use it directly .

Must read : Framework based programs run successfully , For JAR Package version , The correctness of the configuration file has strict requirements , Anything goes wrong , Will cause the framework program to fail . If you are learning this framework for the first time , Be sure to follow the instructions of the tutorial strictly , Completely imitate the operation , Until you successfully see the running effect . After the first success , Confidence , Ideas will have a better cushion , Then according to their doubts , stay “ success ” Make the desired changes and adjustments to your code , This can greatly save learning time , increase of efficiency , Don't change it at once , Create obstacles to your learning
Correct

Step 1 : Run... First , See the effect , Learn again   
Step 2 : Imitation and troubleshooting   
Step 3 : The purpose of this knowledge point is   
Step 4 : New project   
Step 5 : Download package   
Step 6 : Import package   
Step 7 : pojo   
Step 8 : applicationContext.xml   
Step 9 : TestSpring   
Step 10 : schematic diagram   
Step 11 : practice   

Step 1 :

Run... First , See the effect , Learn again

edit top fracture
The old rule , First download the runnable project in the upper right corner , Configure to run , After confirming availability , Then learn what steps have been taken to achieve this effect .
Step 2 :

Imitation and troubleshooting

edit top fracture
After ensuring that the runnable project can run correctly , Then strictly follow the steps in the tutorial , Imitate the code again .
The imitation process inevitably has code differences , As a result, the expected operation results cannot be obtained , At this moment, by comparison The correct answer ( Runnable project ) And your own code , To locate the problem .
In this way , Learning is effective , Troubleshooting is efficient , It can obviously improve the learning speed , Across all the barriers on the way to learning .

It is recommended to use diffmerge Software , Compare folders . Put your own project folder , Compare with my runnable project folder .
This software is awesome , You can know which two files in the folder are wrong , And clearly marked
Here is a green installation and use tutorial : diffmerge Download and use tutorials
Step 3 :

The purpose of this knowledge point is

edit top fracture
This knowledge point can be obtained by running TestSpring Demonstrate how to use Spring Get an object , And print it name
stay e:\project\spring New under directory spring project (java project type )
 New project
Download the... In the upper right corner lib.rar, And unzip it to e:/project/spring/lib Under the directory
 Download package
hold jar Import package into project , Guide package method : Right click project->properties->java build path->libaries->add external jars
 Import package
prepare pojo Category, To demonstrate IOC and DI
package com.how2java.pojo; public class Category { public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } private int id; private String name; }
package com.how2java.pojo;

public class Category {

	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	private int id;
	private String name;
}
stay src New under directory applicationContext.xml File
applicationContext.xml yes Spring Core configuration file , By keyword c You can get Category Object , When the object is obtained , That is, the string is injected "category 1“ To name Property
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <bean name="c" class="com.how2java.pojo.Category"> <property name="name" value="category 1" /> </bean> </beans>
Test code , The demonstration passed spring obtain Category Object , And what the object is injected into name attribute .
As shown in the figure , It can be printed out through Spring Got it Category Of the object name attribute
TestSpring
package com.how2java.test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.how2java.pojo.Category; public class TestSpring { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "applicationContext.xml" }); Category c = (Category) context.getBean("c"); System.out.println(c.getName()); } }
package com.how2java.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.how2java.pojo.Category;

public class TestSpring {

	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext(
				new String[] { "applicationContext.xml" });

		Category c = (Category) context.getBean("c");
		
		System.out.println(c.getName());
	}
}
Compare by getting objects

The traditional way :
Through new Keyword actively create an object
IOC Way
The life cycle of an object is determined by Spring To manage , Directly from Spring There to get an object . IOC yes Reverse control (Inversion Of Control) Abbreviation for , It's like control is in your own hands , To Spring.

Make an analogy :
The traditional way : It's equivalent to going to the vegetable market yourself new I found a chicken , It's just raw chicken , Pluck your own hair , Eviscerate , And pepper , soy sauce , Bake , After various processes , Before you can eat .
use IOC: It's like going to a restaurant (Spring) Ordered a chicken , When it's in your hands , It has everything , You just eat .
 schematic diagram
Step 11 :

practice

edit top fracture   Wrong posture , get half the results with double the effort ! Click to see the correct posture for the exercise
use IOC The way , Get a Product Object


The official account of programming , Follow and get the latest tutorials and promotions in real time , thank you .


Q & A area    
2021-02-05 Cannot resolve property 'name'
Attention_1Dark

about JAVA Frame -Spring-IOC/DI Your questions



Cannot resolve property 'name' What's the problem ,name It's always red
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
   http://www.springframework.org/schema/beans 
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/aop 
   http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
   http://www.springframework.org/schema/tx 
   http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
   http://www.springframework.org/schema/context      
   http://www.springframework.org/schema/context/spring-context-3.0.xsd">
 
    <bean name="c" class="com.how2java.pojo.Category">
        <property name="name" value="category 1" />
    </bean>
 
</beans>
 
               


6 One answer

wuxinmuou
Answer time :2021-09-06
If only the attribute name is red , Because the attribute is not added setter method .

Don't sue Qingfeng
Answer time :2021-08-23
Generally, the marked red path is wrong , This property cannot be found , Look, is this your path ?class="com.how2java.pojo.Category", You need to fill in the real path of your own project file .

Wang Xizhi
Answer time :2021-07-03
<bean name="c" class="com.how2java.pojo.Category">4 Put the words in your sentence Category The path is right , Don't copy directly , paste . Haven't you configured yet phth Are you

zhang11111111
Answer time :2021-04-23
This error report should be before and after name Not right . Look at you Category Whether the parameters in the class are like this

be stranded CN
Answer time :2021-03-02
Successful people came to report , Finally , first Spring. 2021 year 3 month 2 day 17:43:09 record .

wanglin
Answer time :2021-02-15
You are running the project directly using the website I wrote it myself



The answer has been submitted successfully , Auditing . Please My answer Check the answer record at , thank you
answer Or code please Fill in at least one , If you have a problem , Please ask again , Otherwise, the webmaster may not see





2021-01-15 idea Created project
yexin

about JAVA Frame -Spring-IOC/DI Your questions
idea The created project does not have lib folder , that lib.rar Where should I put my bag




3 One answer

wanglin
Answer time :2021-02-15
It doesn't matter where you put it The point is your configuration reason why We have to follow The location of the website Because That's the default location Those configurations default

Sad migrant workers
Answer time :2021-02-14
I put src There's no problem below , Right? xml The file name is incorrect ?

Shelly_Grid
Answer time :2021-01-27
Put it directly under the project root directory , Not src Or WEB-INF Next



The answer has been submitted successfully , Auditing . Please My answer Check the answer record at , thank you
answer Or code please Fill in at least one , If you have a problem , Please ask again , Otherwise, the webmaster may not see




2020-10-30 this spring.rar Nothing has changed , Still can't run , How can it run
2020-10-28 use IDEA maven My little friend, pay attention
2020-07-09 about applicationContext.xml Configuration information problem


Too many questions , Page rendering is too slow , To speed up rendering , Only a few questions are displayed on this page at most . also 68 Previous questions , please Click to view

Please... Before asking questions land
The question has been submitted successfully , Auditing . Please My question Check the question record at , thank you
about JAVA Frame -Spring-IOC/DI Your questions

Try to provide Screenshot code and Abnormal information , Help to analyze and solve problems . You can also enter this station QQ Group communication : 496725845
Ask questions and try to provide complete code , Environment description , The more conducive to the recurrence of the problem , The faster your question can be answered .
Have questions about the code in the tutorial , Please provide which step , Which line is in doubt , This makes it easy to quickly locate the problem , Improve the speed at which questions are answered
In the thousands of questions that already exist , A considerable proportion , Because of the use of and webmaster Different versions of the development environment Resulting in , For example jdk, eclpise, idea, mysql,tomcat Wait, the version of the software is inconsistent .
Please use the same version as the webmaster , You can save yourself a lot of learning time . The webmaster sorted out the software versions used in teaching , It's all here , Convenient for everyone to download : /k/helloworld/helloworld-version/1718.html

Upload screenshot