博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用IDEA搭建spring
阅读量:6889 次
发布时间:2019-06-27

本文共 2158 字,大约阅读时间需要 7 分钟。

  从前使用eclipse开发,集成jar包,现在使用maven来管理

一:

1.框架

  

 

2.pom

  需要spring core与spring context。

1 
2
5
4.0.0
6 7
SpringTest
8
SpringTest
9
1.0-SNAPSHOT
10 11
12
13
14
org.springframework
15
spring-core
16
5.0.0.RELEASE
17
18
19
20
org.springframework
21
spring-context
22
5.0.0.RELEASE
23
24 25
26

 

3.接口HelloWorld

1 package com.it.service;2 3 public interface HelloWorld {4     public void sayHello();5 }

 

4.实现类

1 package com.it.service;2 3 public class SpringHelloWorld implements HelloWorld {4 5     public void sayHello() {6         System.out.println("say hello");7     }8 }

 

5.bean

1 package com.it.bean; 2  3 import com.it.service.HelloWorld; 4  5 public class HelloWorldService { 6     private HelloWorld helloWorld; 7  8     public HelloWorldService() { 9 10     }11 12     public void setHelloWorld(HelloWorld helloWorld) {13         this.helloWorld = helloWorld;14     }15 16     public HelloWorld getHelloWorld() {17         return this.helloWorld;18     }19 }

 

6.运行main

1 package com.it.main; 2  3 import com.it.service.HelloWorld; 4 import com.it.bean.HelloWorldService; 5 import org.springframework.context.ApplicationContext; 6 import org.springframework.context.support.ClassPathXmlApplicationContext; 7  8 public class HelloMain { 9     public static void main(String[] args) {10 11         ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");12 13         HelloWorldService service = (HelloWorldService) context.getBean("helloWorldService");14 15         HelloWorld hw= service.getHelloWorld();16 17         hw.sayHello();18     }19 }

 

7.beans.xml

1 
2
5 6
7
8
9 10
11

 

8.效果

  

 

转载地址:http://xhqbl.baihongyu.com/

你可能感兴趣的文章
Robot Framework + Selenium library + IEDriver环境搭建
查看>>
第220天:Angular---路由
查看>>
Android中XML解析-PULL解析
查看>>
mysql小记--基础知识
查看>>
Java验证码
查看>>
vue 编辑
查看>>
【状压DP】【NOIP提高组】愤怒的小鸟
查看>>
MVC, MVP, MVVM总结——MVC篇
查看>>
汤炒栗子
查看>>
四川大学师生莅临现场
查看>>
跨域ajax原理(jsonp方式)
查看>>
Discover a powerful and suitable Javascript Automatic Testing Toolkit
查看>>
软件测试第三次作业
查看>>
bzoj 4372 烁烁的游戏——动态点分治+树状数组
查看>>
检测浏览器版本太低 提示用户下载其他浏览器
查看>>
Evosuite使用方法入门
查看>>
Python urllib模块
查看>>
VC++ CStatic控件背景透明且改变其文本时,文字重叠解决方法
查看>>
WPF学习笔记——ListBox用ItemsSource绑定数据源
查看>>
ASP.NET MVC中的嵌套布局页
查看>>