Java Spring快速入門(mén)
一、Spring是什么?
- Spring是一個(gè)開(kāi)源框架,
- Spring為簡(jiǎn)化企業(yè)級(jí)應(yīng)用開(kāi)發(fā)而生,使用Spring可以使簡(jiǎn)單的JavaBean實(shí)現(xiàn)以前只有EJB才能實(shí)現(xiàn)的功能。
- Spring是一個(gè)IOC(DI)和AOP容器框架。
二、具體描述Spring
- 輕量級(jí):Spring是非侵入式的-基于Spring開(kāi)發(fā)的應(yīng)用中的對(duì)象可以不依賴(lài)Spring的API
- 依賴(lài)注入:(DI-Dependency injection、IOC)
- 面向切面編程:(AOP-aspect oriented programming)
- 容器:Spring是一個(gè)容器,因?yàn)樗⑶夜芾響?yīng)用對(duì)象的生命周期
- 框架:Spring實(shí)現(xiàn)了使用簡(jiǎn)單的組件配置組合成一個(gè)復(fù)雜的應(yīng)用,在Spring中可以使用XML和java注解組合這些對(duì)象
- 一站式:在IOC和AOP的基礎(chǔ)上可以整合各種企業(yè)應(yīng)用的開(kāi)源框架和優(yōu)秀的第三方類(lèi)庫(kù)(實(shí)際上Spring自身也提供了展現(xiàn)層的SpringMVC和持久層的Spring JDBC)
三、搭建Spring環(huán)境
1. eclipse安裝Spring Tool Suite
SPRING TOOL SUITE 是一個(gè) Eclipse 插件,利用該插件可以更方便的在 Eclipse 平臺(tái)上開(kāi)發(fā)基于 Spring 的應(yīng)用。
2. 加包
把以下的jar包加入到工程的classpath:

3. Spring的配置文件:一個(gè)典型的Spring項(xiàng)目需要?jiǎng)?chuàng)建一個(gè)或多個(gè)Bean配置文件,這些配置文件用于在Spring IOC容器中配置Bean。Bean的配置文件可以放在classpath下,也可以放在其他目錄下。
4. 建立Spring項(xiàng)目,編寫(xiě)HelloWorld:
package com.atguigu.spring.beans;
public class HelloWorld {
private String name;
public void setName(String name) {
System.out.println("setName...");
this.name = name;
}
public void hello(){
System.out.println("Hello " + name);
}
public HelloWorld() {
System.out.println("HelloWorld's construct...");
}
}
<?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:util="http://www.springframework.org/schema/util"
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 http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
<bean id="helloworld" class="com.atguigu.spring.beans.HelloWorld">
<property name="name" value="spring"></property>
</bean>
</beans>
package com.atguigu.spring.beans;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Main {
public static void main(String[] args) {
/*
HelloWorld helloWorld = new HelloWorld();
helloWorld.setName("spring");
helloWorld.hello();
*/
//1.創(chuàng)建容器
ApplicationContext ctx = new ClassPathXmlApplicationContext("appliactionContext.xml");
//2.從容器中獲取bean
HelloWorld hello = (HelloWorld) ctx.getBean("helloworld");
//3.調(diào)用bean的方法
hello.hello();
}
}
5.測(cè)試結(jié)果

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!
- Java Spring Controller 獲取請(qǐng)求參數(shù)的幾種方法詳解
- Java SpringMVC實(shí)現(xiàn)PC端網(wǎng)頁(yè)微信掃碼支付(完整版)
- Java Spring 事務(wù)回滾詳解
- Java Spring MVC 上傳下載文件配置及controller方法詳解
- C程序函數(shù)調(diào)用&系統(tǒng)調(diào)用
- 從最基本的Java工程搭建SpringMVC+SpringDataJPA+Hibernate
- 實(shí)例講解Java的Spring框架中的AOP實(shí)現(xiàn)
- 詳解Java Spring各種依賴(lài)注入注解的區(qū)別
- 在Java的Spring框架中配置Quartz的教程
- Java類(lèi)獲取Spring中bean的5種方式
- 詳解Java的Spring框架中的事務(wù)管理方式
相關(guān)文章
基于IDEA創(chuàng)建SpringMVC項(xiàng)目流程圖解
這篇文章主要介紹了基于IDEA創(chuàng)建SpringMVC項(xiàng)目流程圖解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-10-10
java fastJson轉(zhuǎn)JSON兩種常見(jiàn)的轉(zhuǎn)義操作
在實(shí)際開(kāi)發(fā)中,我們有時(shí)需要將特殊字符進(jìn)行轉(zhuǎn)義,本文主要介紹了java fastJson轉(zhuǎn)JSON兩種常見(jiàn)的轉(zhuǎn)義操作,具有一定的參考價(jià)值,感興趣的可以了解一下2024-03-03
Java多線程Callable接口實(shí)現(xiàn)代碼示例
相信大家對(duì)Java編程中如何創(chuàng)建線程已經(jīng)不陌生了,這篇文章就向朋友們介紹實(shí)現(xiàn)callable接口,具體實(shí)例詳見(jiàn)正文。2017-10-10
java中l(wèi)ambda(函數(shù)式編程)一行解決foreach循環(huán)問(wèn)題
這篇文章主要介紹了java中l(wèi)ambda(函數(shù)式編程)一行解決foreach循環(huán)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-07-07
Caused by: java.io.IOException: DerInputStrea
這篇文章主要介紹了Caused by: java.io.IOException: DerInputStream.getLength(): lengthTag=111, too big,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2024-10-10

