當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
【Spring】入门HelloWorld
生活随笔
收集整理的這篇文章主要介紹了
【Spring】入门HelloWorld
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
參考:https://www.yiibai.com/spring/spring-tutorial-for-beginners.html
一、創建項目
1.利用IntelliJ創建Maven項目
2.配置pom.xml,引入Spring
4.0.0
二、編寫HelloWorld
1.編寫接口類HelloWorld
public interface HelloWorld {public void sayHello(); }2.編寫實現類HellWorldImplOne
public class HellWorldImplOne implements HelloWorld {public void sayHello() {System.out.println("hello one");} }3. 編寫依賴類HelloWordDependanceTest
public class HelloWordDependanceTest {private HelloWorld helloWorld;public void setHelloWorld(HelloWorld helloWorld) {this.helloWorld = helloWorld;}public HelloWorld getHelloWorld() {return this.helloWorld;}}4.編寫測試類HelloWorldDependanceMain
public class HelloWorldDependanceMain {public static void main(String[] args){ApplicationContext context =new ClassPathXmlApplicationContext("bean.xml");HelloWordDependanceTest service =(HelloWordDependanceTest) context.getBean("helloWorldDependanceTest");HelloWorld hw= service.getHelloWorld();hw.sayHello();} }5.編寫配置文件bean.xml
<?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"><bean id="HelloWorldImplOne" class="com.jh.spring.HellWorldImplOne"></bean><bean id="helloWorldDependanceTest" class="com.jh.spring.HelloWordDependanceTest"><property name="helloWorld" ref="HelloWorldImplOne"/></bean> </beans>6.運行測試類HelloWorldDependanceMain
轉載于:https://www.cnblogs.com/grape1211/p/9426208.html
總結
以上是生活随笔為你收集整理的【Spring】入门HelloWorld的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 假期第四周周总结
- 下一篇: Python的看门狗实现自动化实时对服务