Java Spring Tutorial -- Spring框架和commons-logging

文件结构:

Java Spring Tutorial -- Spring框架和commons-logging_第1张图片

MessageBean.java

package com.zxl.spring;

public class MessageBean {
	private String message;

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
}

SpringApp01.java

package com.zxl.spring;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringApp01 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext("SpringBeans.xml");
		MessageBean messageBean =(MessageBean)applicationContext.getBean("messageBean");
		System.out.println(messageBean.getMessage());
		((ConfigurableApplicationContext)applicationContext).close();
	}

}

SpringBeans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://www.springframework.org/schema/beans"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
	<bean id="messageBean" class="com.zxl.spring.MessageBean">
		
		<property name="message" value="thank you for watching zxl spring! " />
		
	</bean>
</beans>


Java Spring Tutorial -- Spring框架和commons-logging_第2张图片


spring-framework & commons-logging


Demo download







你可能感兴趣的:(Java Spring Tutorial -- Spring框架和commons-logging)