标签:5.3 Java name EE Spring jar SPRING% context spring
结构图
源码
User
package cn.edu;
public class User{
private Long id;
private String name;
public Long getId(){
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
applicationContext
<?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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="user" name="u,u1" class="cn.edu.User" scope = "singleton">
<!-- Propeties Injection Dependency -->
<property name = "id" value = "2019216584" />
<property name = "name" value = "丁帅帅" />
</bean>
<bean id="user2" name="u2" class="cn.edu.User" scope = "singleton">
<!-- Propeties Injection Dependency -->
<property name = "id" value = "2019216584" />
<property name = "name" value = "丁帅帅" />
</bean>
</beans>
DemoSpringApp
import org.springframework.context.ApplicationContext;
import cn.edu.*;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.SpringVersion;
public class DemoSpringApp
{
public static void main( String[] args )
{
// Using XML File to initialize container.
// AbstractApplicationContext context = new
// ClassPathXmlApplicationContext("/applicationContext.xml",DemoSpringApp.class);
AbstractApplicationContext context = new
ClassPathXmlApplicationContext("/applicationContext.xml");
// Get SpringVersion
System.out.println("Spring Version: "+SpringVersion.getVersion());
// Get a Bean
User user1= (User) context.getBean("u1");
User user2= (User) context.getBean("u2");// 运行一次后,把u2改为u1查看运行结果有什么不一样
// Execute a method of the Bean
// // hashCode()取得的是对象的哈希码,哈希码一样说明是同一个对象
// 这个实验要看看从一个Bean配置是否是单例模式
System.out.println("user1 hashCode = "+user1.hashCode());
System.out.println("user2 hashCode = "+user2.hashCode());
System.out.println("user1's id = "+user1.getId()
+" | user1's name ="+user1.getName());
System.out.println("user2's id = "+user2.getId()
+" | user2's name ="+user2.getName());
context.registerShutdownHook();
context.close();
}
}
Spring5版
1.编译内容(jc.bat)
setlocal
set "SPRING=.\spring\"
javac -cp ".;%SPRING%javax.inject-1.jar;%SPRING%javax.servlet-api-4.0.1.jar;%SPRING%junit-3.8.1.jar;%SPRING%spring-aop-5.3.8.jar;%SPRING%spring-beans-5.3.8.jar;%SPRING%spring-context-5.3.8.jar;%SPRING%spring-core-5.3.8.jar;%SPRING%spring-expression-5.3.8.jar;%SPRING%spring-jcl-5.3.8.jar" -encoding "UTF-8" DemoSpringApp.java
2.编译截图
3.运行内容(jrun.bat)
setlocal
set "SPRING=.\spring\"
java -cp ".;%SPRING%javax.inject-1.jar;%SPRING%javax.servlet-api-4.0.1.jar;%SPRING%junit-3.8.1.jar;%SPRING%spring-aop-5.3.8.jar;%SPRING%spring-beans-5.3.8.jar;%SPRING%spring-context-5.3.8.jar;%SPRING%spring-core-5.3.8.jar;%SPRING%spring-expression-5.3.8.jar;%SPRING%spring-jcl-5.3.8.jar" DemoSpringApp
4.运行截图
Spring4版
1.编译
setlocal
set "SPRING=.\spring4\"
javac -cp ".;%SPRING%spring-beans-4.1.6.RELEASE.jar;%SPRING%spring-core-4.1.6.RELEASE.jar;%SPRING%spring-context-4.1.6.RELEASE.jar;" -encoding "UTF-8" -Xlint:deprecation %1
2.运行
setlocal
set "SPRING=.\spring4\"
java -cp ".;%SPRING%spring-beans-4.1.6.RELEASE.jar;%SPRING%spring-core-4.1.6.RELEASE.jar;%SPRING%spring-context-4.1.6.RELEASE.jar;%SPRING%spring-expression-4.1.6.RELEASE.jar;%SPRING%commons-logging-1.1.1.jar;" %1
修改后的截图
标签:5.3,Java,name,EE,Spring,jar,SPRING%,context,spring 来源: https://www.cnblogs.com/dss-99/p/15410538.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。