Spring 简单入门实例

  • 首先新建一个Web 项目
  • 导入相应Jar 包Spring 简单入门实例
  • <?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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd">
    <bean id="say" class="com.hh.spring.SpringTest">
    <property name="name" value="张嘎"></property>
    <property name="content" value="三天不打小鬼子,手都痒痒!"></property>
    </bean> </beans>

      

  • package com.hh.spring;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext; public class SpringTest { private String name; private String content; public String getName() {
    return name;
    } public void setName(String name) {
    this.name = name;
    } public String getContent() {
    return content;
    } public void setContent(String content) {
    this.content = content;
    } private void say(){
    System.out.println(name+"说:"+content);
    } public static void main(String[] args) {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
    SpringTest zhangGa = ctx.getBean("say",SpringTest.class);
    zhangGa.say();
    }
    }

      

上一篇:Centos6.5使用ELK(Elasticsearch + Logstash + Kibana) 搭建日志集中分析平台实践


下一篇:使用SqlBulkCopy, 插入整个DataTable中的所有数据到指定数据库中