发表于: 2017-07-03 21:21:19

1 1194


今天完成的事情:

1.安装Spring 出了问题,解决不了,只能重装eclipse,一下为出错截图


(发现新安装的不需要配置,和原来的一样,两个eclipse用的是同一配置文件?)

2.通过eclipse安装spring

3. 完成spring 下的HelloWorld

    文件分为三部分:Bean的配置文件

                                主函数MainApp

                                HelloWorld

     通过依赖注入完成输出:你的消息:Hello World!

                                 



明天计划的事情:

1. .深入学习依赖注入

    Spring使用Setter依赖注入

    Spring通过构造方法依赖注入

    Spring构造方法注入类型歧义

2.Spring松耦合实例

3. 有时间的话学习注解

遇到的问题:

1.安装Spring 出了问题,解决不了,只能重装eclipse

    (新下的eclipse是4.7正式版的,那原来是什么,测试吗)



收获:

1.安装Spring

 ①查询eclipse的版本

  Help --> About Eclipse

 


②在http://spring.io/tools/sts/all 页面找到对应版本的下载链接

③下载spring :Eclipse -> Help -> Install Software  -> Work with 

填写上图的下载链接,回车,选则所有的spring IDE选项下载

勾去自动更新

一路NEXT完成。



2.Hello World 实例

① File-->new-->Other选择如下图的创建


② 新建一个HelloWorld.java

package com.tutorialspoint;

public class HolleWorld {

       //message为Beans.xml的property name  

   //通过value="Hello World!"赋予message字符串

       private String message;

       public void setMessage(String message) {

             this.message = message;

       }

       public void getMessage() {

            System.out.println("你的消息:" + message)

       }

 } 


③   创建MainApp.java 

package com.tutorialspoint;

import org.springframework.context.ApplicationContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainApp {

       public static void main(String[] args) {

               //获取Spring的Beans.xml配置文件,注入IOC容器中 

               ApplicationContext context = 

                         new ClassPathXmlApplicationContext("Beans.xml");

               //调用HolleWorld.java , “holleWorld”为Beans.xml中bean id

              HolleWorld obj = (HolleWorld) context.getBean("holleWorld");

              obj.getMessage();

        }

}


④ 编写配置文件Beans.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-3.0.xsd">

      // 配置需要被Spring管理的Bean创建,创建后放在了Spring IOC容器里面

      <bean id="holleWorld" class="com.tutorialspoint.HolleWorld">

              <property name="message" value="Hello World!"/>

     </bean>

</beans>


⑤ 运行结果



参考资料:

Spring hello world实例

Hello World 实例

Spring配置及第一个Spring HelloWorld




PS  : 已经报上名了,明天去郑州分院看看住宿的地方

PS2: 希望能有个题目,把以前学的任务能串联起来,感觉知识点太零碎了

PS3: JAVA语法只学了一半,很担心入学后跟不上。




返回列表 返回列表
评论

    分享到