Eclipse install spring-tools and helloWorld Case

Preparing the environment: 

Download zip package: https://spring.io/tools3/sts/all/ zip package downloaded from the following

Plug Help ==> Install New SoftWare

Click on the following zip package after the Archive download a good choice

Can be selected as follows

 

Then the back of the consent agreement or something all the way next to the last finish

Then in the bottom right corner of the window a progress bar to install plug-in, waiting for pop. Finally, you will be asked to restart the eclipse. It can restart.

window ==> preference can see already installed in the following figure

 

 

The Hello World Spring Case:

You need five jar package:

  1. commons-logging
  2. spring-beans
  3. spring-context
  4. spring-core
  5. spring-expresso

Which contains a spring-beans, spring-context, spring-core, spring-expresso four jar package

Then copied to the project src / lib Build Path and add to jar library project

 

The following is added after the project is good

  1. Creating the HelloWorld objects

    HelloWorld.java

    public class HelloWorld {
    	
    	private String name;
    	
    	public void setName(String name) {
    		this.name=name;
    	}
    	
    	public void hello() {
    		System.out.println("hello "+name);
    	}
    
    }
  2. Creating springIOC container in the configuration file src applicationContext.xml


    In <beans> </ beans> tag added <bean> </ bean> tag is as follows

    <!-- helloworldBean配置 -->
    	<bean id="helloWorld" class="com.taotao.beans.HelloWorld">
    		<property name="name"  value="spring" ></property>
        </bean>
  3. Main function call three steps:
		//获取spring ioc容器(从配置的xml文件中获取)
		ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
		
		//获取bean
		HelloWorld helloWorld=(HelloWorld)ctx.getBean("helloWorld");
		
		//调用hello方法
		helloWorld.hello();

 

You can execute the main method

Screenshot analysis code :( enlarged view)

发布了242 篇原创文章 · 获赞 13 · 访问量 1万+

Guess you like

Origin blog.csdn.net/qq_41813208/article/details/103625666