码迷,mamicode.com
首页 > 编程语言 > 详细

【软件工程】搭建Spring 的入门程序

时间:2020-01-22 01:29:01      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:pid   ted   ase   utf-8   static   cti   text   ram   out   

搭建Spring 的入门程序

摘抄内容

技术图片

 

技术图片

 

 

 

 技术图片

 

 

 

 

运行结果

技术图片

 

相关代码

pom.xml

 1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 2   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 3   <modelVersion>4.0.0</modelVersion>
 4   <groupId>com.ssm</groupId>
 5   <artifactId>test</artifactId>
 6   <packaging>war</packaging>
 7   <version>0.0.1-SNAPSHOT</version>
 8   <name>test Maven Webapp</name>
 9   <url>http://maven.apache.org</url>
10   <dependencies>
11     <dependency>
12       <groupId>junit</groupId>
13       <artifactId>junit</artifactId>
14       <version>3.8.1</version>
15       <scope>test</scope>
16     </dependency>
17     <!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
18 <dependency>
19     <groupId>org.springframework</groupId>
20     <artifactId>spring-core</artifactId>
21     <version>5.0.4.RELEASE</version>
22 </dependency>
23     <!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
24 <dependency>
25     <groupId>org.springframework</groupId>
26     <artifactId>spring-context</artifactId>
27     <version>5.0.4.RELEASE</version>
28 </dependency>
29     <!-- https://mvnrepository.com/artifact/org.springframework/spring-expression -->
30 <dependency>
31     <groupId>org.springframework</groupId>
32     <artifactId>spring-expression</artifactId>
33     <version>5.0.4.RELEASE</version>
34 </dependency>
35     <!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
36 <dependency>
37     <groupId>org.springframework</groupId>
38     <artifactId>spring-beans</artifactId>
39     <version>5.0.4.RELEASE</version>
40 </dependency>
41     
42   </dependencies>
43   <build>
44     <finalName>test</finalName>
45   </build>
46 </project>

 

applicationContext.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4 xsi:schemaLocation="http://www.springframework.org/schema/beans
 5 http://www.springframework.org/schema/beans/spring-beans.xsd">
 6 <bean id="helloSpring" class="com.ssm.HelloSpring">
 7 <property name="userName" value="张三">
 8 
 9 </property>
10 </bean>
11 
12 </beans>

 

HelloSpring.java

 1 package com.ssm;
 2 
 3 public class HelloSpring {
 4     private String userName;
 5     public void setUserName(String userName) {
 6         this.userName=userName;
 7     }
 8     public void show() {
 9         System.out.println(userName + ":欢迎您来学习Spring 框架");
10     }
11 }

 

TestHelloSpring.java

 1 package com.ssm;
 2 import org.springframework.context.ApplicationContext;
 3 import org.springframework.context.support.ClassPathXmlApplicationContext;
 4 public class TestHelloSpring {
 5 
 6     public static void main(String[] args) {
 7         // TODO Auto-generated method stub
 8         ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
 9         HelloSpring helloSpring =(HelloSpring)ctx.getBean("helloSpring");
10         helloSpring.show();
11     }
12 
13 }

【软件工程】搭建Spring 的入门程序

标签:pid   ted   ase   utf-8   static   cti   text   ram   out   

原文地址:https://www.cnblogs.com/yyyyfly1/p/12227389.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!