idea spring helloworld
由于近期在學(xué)習(xí)JAVA的一些基礎(chǔ)知識(shí),發(fā)現(xiàn)出現(xiàn)只停留在一些簡(jiǎn)單的方法上的感覺(jué)。今天特定向下一個(gè)目標(biāo)spring學(xué)習(xí)一下。今天自學(xué)了一下idea下學(xué)習(xí)spring的helloworld開(kāi)始。
1:下載common-logging JAR包
http://mirrors.shu.edu.cn/apache/commons/logging/binaries/? ?
? ? ? ?下載并解壓丟到 D:/java/common-logging/lib目錄下
?
2:新建demo項(xiàng)目
step1:選擇spring框架
? ? ? ?step2:選擇項(xiàng)目地址
? ? ? ?step3:下載spring框架相應(yīng)版本lib
3:導(dǎo)入common-logging庫(kù)
4:編碼
step1 :在src目錄下新建一個(gè)package? ?cc.freshair
? ? ? ?step2:在src/cc.freshair目錄下建立兩個(gè)類(HelloWorld.php? ?,MainApp.java)
? ?HelloWorld.java
package cc.freshair;/*** 描述:* <p>* Author: dxh20012012001@sina.com* Created: 2018/5/20* Version: V1.0*/ public class HelloWorld {private String name;public String getName() {return name;}public void setName(String name) {this.name = name;}public void sayHello() {System.out.println("Hello World");} }?
MainApp.java
package cc.freshair;import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;/*** 描述:* <p>* Author: dxh20012012001@sina.com* Created: 2018/5/20* Version: V1.0*/ public class MainApp {public static void main(String[] args) {ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-config.xml");HelloWorld helloWorld = (HelloWorld) applicationContext.getBean("HelloWorld");helloWorld.sayHello();System.out.println(helloWorld.getName());} }?
? ? ? ?step3:修改src/spring-config.xml文件添加一個(gè)bean映射
<?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="HelloWorld" class="cc.freshair.HelloWorld">
<property name="name" value="Spring"></property>
</bean>
</beans>
step4:整體結(jié)構(gòu)
?
? ? ? ?5:運(yùn)行
?
? ? ? ?參考來(lái)源:
?極客學(xué)院(HelloWorld)?? http://wiki.jikexueyuan.com/project/spring/hello-world-example.html
轉(zhuǎn)載于:https://www.cnblogs.com/amuge/p/9064547.html
總結(jié)
以上是生活随笔為你收集整理的idea spring helloworld的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 带left join 的sql的执行顺序
- 下一篇: spring boot (3.自动配置@