• spring ico


    代码非常简单。如果缺少jar包将导致报错。

    需要5个spring jar包和1个logging jar,否则报错。 

    org.springframework.asm.jar
    org.springframework.core.jar
    org.springframework.beans.jar
    org.springframework.context.jar
    org.springframework.expression.jar

    定义一个接口,一个实现类。java project项目。

    package ioc;
    public interface HelloApi {
        public void sayHello();  
    }
    package ioc;
    public class Hello implements HelloApi{
        @Override
        public void sayHello() {  
            System.out.println("Hello World!");  
     } 
    }
    package ioc;
    
    import org.springframework.context.ApplicationContext;  
    import org.springframework.context.support.ClassPathXmlApplicationContext;  
    public class HelloTest {    
        public static  void main(String[] args) {  
            ApplicationContext context = new ClassPathXmlApplicationContext("helloworld.xml");  
             HelloApi helloApi = context.getBean("hello", HelloApi.class);  
             helloApi.sayHello();         
      }  
    }

      

    <?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: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/context                http://www.springframework.org/schema/context/spring-context-3.0.xsd">  
      <!-- id 表示你这个组件的名字,class表示组件类 -->  
    <bean id="hello" class="ioc.Hello"></bean>  
    </beans> 

     不清楚如何找到该xml文件。

     ApplicationContext context = new ClassPathXmlApplicationContext("helloworld.xml"); 
  • 相关阅读:
    iframe子页面获取父页面元素和window对象
    jQuery使用blur()方法触发两次的解决方法
    java使用freemarker生成word
    java实现下载文件
    IE11中实现颜色渐变
    MYSQL中INET_ATON()函数
    数据库SQL实战(1)
    MYSQL表中向SET类型的字段插入值时值之间不能有空格
    MYSQL表中设置字段类型为TIMESTAMP时的注意事项
    SQL中判断值是否为NULL
  • 原文地址:https://www.cnblogs.com/lucika/p/spring.html
Copyright © 2020-2023  润新知