日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring之HelloWorld

發布時間:2024/4/13 javascript 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring之HelloWorld 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

搭建 Spring 開發環境

把以下 jar 包加入到下:
工程的 classpath?

Spring 的配置文件: 一個典型的 Spring 項目需要創建一個或多個 Bean 配置文件, 這些配置文件用于在 Spring IOC 容器里配置 Bean. Bean 的配置文件可以放在 classpath 下, 也可以放在其它目錄下.

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"><!-- id:bean的唯一標識class:指定全類名 反射的方式創建對象: Class cls = Class.forName("com.learn.spring.beans.HelloWorld")Object obj = cls.newInstance(); // 需要提供默認的構造器.property: 通過set方法給指定的屬性賦值--><bean id="helloWorld" class="com.learn.spring.beans.HelloWorld"><property name="name1" value="Jerry"></property></bean> </beans> package com.learn.spring.beans;public class HelloWorld {private String name ;public HelloWorld() {System.out.println("invoke HelloWorld Constructor.....");}public String getName() {return name;}public void setName1(String name) {System.out.println("invoke HelleWorld setName......");this.name = name;} public void sayHello(){System.out.println("my name 's " + name );}} package com.learn.spring.test;import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;public class Main {public static void main(String[] args) {/*//1.new 對象HelloWorld helloWorld = new HelloWorld();//2.給name屬性賦值helloWorld.setName("Tom");*///1.獲取IOC容器ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");//2.從IOC容器中獲取對象.//HelloWorld helloWorld = (HelloWorld)ctx.getBean("helloWorld"); //3.調用方法helloWorld.sayHello(); } }

?

總結

以上是生活随笔為你收集整理的Spring之HelloWorld的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。