idea spring helloworld
由于近期在學習JAVA的一些基礎知識,發現出現只停留在一些簡單的方法上的感覺。今天特定向下一個目標spring學習一下。今天自學了一下idea下學習spring的helloworld開始。
1:下載common-logging JAR包
http://mirrors.shu.edu.cn/apache/commons/logging/binaries/? ?
? ? ? ?下載并解壓丟到 D:/java/common-logging/lib目錄下
?
2:新建demo項目
step1:選擇spring框架
? ? ? ?step2:選擇項目地址
? ? ? ?step3:下載spring框架相應版本lib
3:導入common-logging庫
4:編碼
step1 :在src目錄下新建一個package? ?cc.freshair
? ? ? ?step2:在src/cc.freshair目錄下建立兩個類(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文件添加一個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:整體結構
?
? ? ? ?5:運行
?
? ? ? ?參考來源:
?極客學院(HelloWorld)?? http://wiki.jikexueyuan.com/project/spring/hello-world-example.html
轉載于:https://www.cnblogs.com/amuge/p/9064547.html
總結
以上是生活随笔為你收集整理的idea spring helloworld的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 带left join 的sql的执行顺序
- 下一篇: spring boot (3.自动配置@