Spring配置文件以及基本常识

来源:互联网 发布:java语言 编辑:程序博客网 时间:2024/06/09 19:32
package com.ant.spring;public class HellWorld {private String name;public String getName() {return name;}public void setName(String name) {this.name = name;}       //构造器public void hell() {System.out.println("hell:"+this.name);}}
<?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.xsd"> <!--  注入方式:        1.getter setters(常用)        2.构造器注入(死的应用)        3.接口注入(不常用,不推荐)       通过getters setters注入配置spring class:bean的全类名(包名+实体类类名),通过反射的方式在IOC容器中创建bean,并要求bean中必须有无参的构造器id:标识容器中的bean.id 唯一--><bean id
package com.ant.spring;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class Main {public static void main(String[] args) {//1.创建spring的IOC容器对象,并根据spring.xml文件实例化对象,调用property配置进行赋值//ApplicationContext代表IOC容器//ClassPathXmlApplicationContext:是ApplicationContext的实现类ApplicationContext con=new ClassPathXmlApplicationContext("spring.xml");//2.从IOC容器中获取bean并实例,利用id定位到IOCHellWorld hellWorld=(HellWorld) con.getBean("hellworld");hellWorld.hell();}}



原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 饮水机放桶漏水怎么办 热水器热水阀门漏水怎么办 热水器热水出口漏水怎么办 热水器上水管漏水怎么办 水管往外漏水怎么办 ppr热水管漏水怎么办 大半夜水闸爆了怎么办 热水器不热水了怎么办 水龙头外皮裂了怎么办 电热水龙头坏了怎么办 太阳能存不住水怎么办 混水阀断裂漏水怎么办 洗澡淋浴头漏水怎么办 马桶有异物堵住怎么办 捷达机油盖漏油怎么办 乳化油臭了怎么办 自行车前叉严重生锈怎么办 自行车链条生锈了怎么办 自行车链子生锈了怎么办 对切削液过敏怎么办 齿轮油加到机油怎么办 机油加液压油里怎么办 液压油里面有水怎么办 加油站双层复合管漏油怎么办 预制屋面板底面渗漏怎么办 焊电焊眼睛疼怎么办 下水主管道篦子怎么办 墙里热水管堵了怎么办 热水管堵住了怎么办 热水管堵塞了怎么办 下水道被油渍堵死怎么办 赛欧车门打不开怎么办 气囊开车门变形怎么办 镀烙金属生锈怎么办 热水器角阀漏水怎么办 淋浴头自动出水怎么办 抽水泵烧了怎么办 压力泵不上水怎么办 chnt电表跳闸了怎么办 应急灯故障灯亮怎么办 消防应急灯不亮怎么办