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 idpackage 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();}}
阅读全文
1 0
- Spring配置文件以及基本常识
- spring boot使用基本常识
- Spring学习----------AOP以及Spring配置文件详解
- Spring学习----------AOP以及Spring配置文件详解
- Spring学习----------AOP以及Spring配置文件详解
- 基本常识
- 基本常识
- 基本常识
- 基本常识
- 基本常识
- 基本常识
- xorg 架构 将来 以及一些基本常识浅析
- xorg 架构 将来 以及一些基本常识浅析
- xorg 架构 将来 以及一些基本常识浅析
- xorg 架构 将来 以及一些基本常识浅析
- 《Oracle环境部署、基本常识以及排错》
- eclipse rcp导出乱码以及引入spring配置文件
- Spring mvc注解的学习以及配置文件的解释
- python windows下安装talib
- View那些事儿(1) -- View绘制的整体流程
- 浅谈OSSemPost()和OSSemPend()
- springboot与mybatis整合操作数据库
- 三次握手和四次挥手
- Spring配置文件以及基本常识
- spring boot发布war包,部署到外部tomcat服务器
- Tensorflow模型Android上的使用
- View那些事儿(2) -- 理解MeasureSpec
- 计算机网络--ARP地址解析协议详解
- HDU6153 A Secret 扩展KMP
- Java标识符
- 2017ccpc网络赛——Friend-Graph
- 分治算法详解