Spring4.3学习记录之HelloWorld(一)

访问我的个人博客 秋码个人博客
打开IDEA,创建Maven项目。
Spring4.3学习记录之HelloWorld(一)_第1张图片
打开pom.xml文件,添加Spring依赖。


  4.0.0
  com.zhenqi.study
  spring4-study
  war
  1.0-SNAPSHOT
  spring4-study Maven Webapp
  http://maven.apache.org

  
    
      io.spring.repo.maven.release
      http://repo.spring.io/release/
      false
    
  

  
    
      junit
      junit
      4.12
      test
    

    
      org.springframework
      spring-context
      4.3.8.RELEASE
    

    
      log4j
      log4j
      1.2.17
    

    
      org.slf4j
      slf4j-log4j12
      1.7.21
    

  
  
    spring4-study
  

然后创建一个JavaBean类。

package com.zhenqi;

/**
 * Created by wuming on 2017/7/7.
 */
public class FirstBean {

    private String message;

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}

在resources文件夹下创建applicationContext.xml文件。





    
        
    

最后写个测试类,进行测试下。

package com.zhenqi.test;

import com.zhenqi.FirstBean;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created by wuming on 2017/7/7.
 */
public class FirstBeanTest {

    @Test
    public void testFirstBean(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        FirstBean firstBean=(FirstBean)context.getBean("firstBean");
        System.out.println(firstBean.getMessage());
    }

}

运行后,输出如下。
Spring4.3学习记录之HelloWorld(一)_第2张图片

你可能感兴趣的:(JavaEE)