zoukankan      html  css  js  c++  java
  • 第一个Spring例子

    手动添加sechame文件:

    windows-->preferences-->myeclipse-->files and editors-->xml-->xmlcatalog--->点add--->Key Type中选择URL-->File system-->在dist/resources/spring-beans-2.5.xsd-->Sechema location;

    下载Spring的包

    1.倒入所需要的Spring的jar包

      必须要的两个jar包:dist\spring.jar,lib\jakarta-commons-logging.jar

      如果使用了切面变成,还需要下列jar文件:lib\aspectj\aspectjwear.jar和aspectjrt.jar,lib\cglib\cglib-nodep-2.1_3.jar

      如果使用了JSR-250中的注解:lib\j2ee\common-annotations.jar

    2.建立beans.xml文件

      

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

    <bean id="personService" class="com.cn.service.impl.PersonServiceBean"></bean>
    </beans>

    3.定义一个借口,并写出其实现层:

    package com.cn.service;

    public interface PersonService {

    public abstract void save();

    }

    package com.cn.service.impl;

    import com.cn.service.PersonService;

    public class PersonServiceBean implements PersonService {
    public void save(){
    System.out.println("my name is save method");
    }
    }

    4.通过Spring框架来调用bean中的方法 

    ApplicationContext ctx=new ClassPathXmlApplicationContext("beans.xml");
    PersonService psersonService=(PersonService) ctx.getBean("personService");
    psersonService.save();

      

  • 相关阅读:
    PHP base_convert() 函数详解
    PHP中位运算符
    MySQL中SQL Mode的查看与设置
    HTML 字符实体详情
    php7中 ?? 和 ?: 的区别
    正则表达式详解
    PHP sprintf() 函数详解
    php-config——PHP配置信息的查看
    无界工作记录
    CMake根据平台移植检查设置文件编译选项
  • 原文地址:https://www.cnblogs.com/GodFather001/p/2281725.html
Copyright © 2011-2022 走看看