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

3. Spring的配置文件:一個典型的Spring項(xiàng)目需要創(chuàng)建一個或多個Bean配置文件,這些配置文件用于在Spring IOC容器中配置Bean。Bean的配置文件可以放在classpath下,也可以放在其他目錄下。
4. 建立Spring項(xiàng)目,編寫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.測試結(jié)果

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

