Srping 歷史

一、History of Spring and the Spring Framework

Spring came into being in 2003 as a response to the complexity of the early?J2EE?specifications. While some consider Java EE and its modern-day successor Jakarta EE to be in competition with Spring, they are in fact complementary. The Spring programming model does not embrace the Jakarta EE platform specification; rather, it integrates with carefully selected individual specifications from the traditional EE umbrella:

  • Servlet API (JSR 340)

  • WebSocket API (JSR 356)

  • Concurrency Utilities (JSR 236)

  • JSON Binding API (JSR 367)

  • Bean Validation (JSR 303)

  • JPA (JSR 338)

  • JMS (JSR 914)

  • as well as JTA/JCA setups for transaction coordination, if necessary.

The Spring Framework also supports the Dependency Injection (JSR 330) and Common Annotations (JSR 250) specifications, which application developers may choose to use instead of the Spring-specific mechanisms provided by the Spring Framework. Originally, those were based on common?javax?packages.

As of Spring Framework 6.0, Spring has been upgraded to the Jakarta EE 9 level (e.g. Servlet 5.0+, JPA 3.0+), based on the?jakarta?namespace instead of the traditional?javax?packages. With EE 9 as the minimum and EE 10 supported already, Spring is prepared to provide out-of-the-box support for the further evolution of the Jakarta EE APIs. Spring Framework 6.0 is fully compatible with Tomcat 10.1, Jetty 11 and Undertow 2.3 as web servers, and also with Hibernate ORM 6.1.

Over time, the role of Java/Jakarta EE in application development has evolved. In the early days of J2EE and Spring, applications were created to be deployed to an application server. Today, with the help of Spring Boot, applications are created in a devops- and cloud-friendly way, with the Servlet container embedded and trivial to change. As of Spring Framework 5, a WebFlux application does not even use the Servlet API directly and can run on servers (such as Netty) that are not Servlet containers.

Spring continues to innovate and to evolve. Beyond the Spring Framework, there are other projects, such as Spring Boot, Spring Security, Spring Data, Spring Cloud, Spring Batch, among others. It’s important to remember that each project has its own source code repository, issue tracker, and release cadence. See?spring.io/projects?for the complete list of Spring projects.

Features

  • Core technologies: dependency injection, events, resources, i18n, validation, data binding, type conversion, SpEL, AOP.

  • Testing: mock objects, TestContext framework, Spring MVC Test,?WebTestClient.

  • Data Access: transactions, DAO support, JDBC, ORM, Marshalling XML.

  • Spring MVC?and?Spring WebFlux?web frameworks.

  • Integration: remoting, JMS, JCA, JMX, email, tasks, scheduling, cache and observability.

  • Languages: Kotlin, Groovy, dynamic languages.

舉例:spring mvc+mybatis

1、應用場景:Spring Framework是一個完整的企業級應用框架,可用于構建復雜、高擴展Java應用程序

2、依賴管理:需要手動添加依賴庫??? ?

<dependencies><!-- 測試 --><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency><!--Spring相關依賴--><!--因為webmvc中包含了aop、beans、context、core等依賴--><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>${spring.version}</version></dependency><!-- Servlet的依賴 --><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>3.0.1</version><scope>provided</scope></dependency><dependency><groupId>commons-fileupload</groupId><artifactId>commons-fileupload</artifactId><version>1.2.1</version></dependency><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.2</version></dependency><!-- MySQL Connector --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>${mysql.version}</version></dependency><!-- Spring JDBC --><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>${spring.version}</version></dependency><!-- 數據庫連接池 --><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>${druid.version}</version></dependency><!-- Mybatis的依賴 --><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>${mybatis.version}</version></dependency><!-- MyBatis和Spring的整合依賴 --><dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>${mybatis.spring.version}</version></dependency></dependencies>

3、配置管理:

? ? 3.1、配置web.xml文件?? ???

<!DOCTYPE web-app PUBLIC"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN""http://java.sun.com/dtd/web-app_2_3.dtd" ><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"id="WebApp_ID" version="3.1"><display-name>Archetype Created Web Application</display-name><!-- 指定Spring的核心配置文件 --><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param><!-- 注冊ServletContext監聽器,創建容器對象,并且將ApplicationContext對象放到Application域中 --><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- 解決亂碼的過濾器 --><filter><filter-name>CharacterEncodingFilter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><init-param><param-name>encoding</param-name><param-value>utf-8</param-value></init-param><init-param><param-name>forceEncoding</param-name><param-value>true</param-value></init-param></filter><filter-mapping><filter-name>CharacterEncodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><!--配置前端控制器:DispatcherServlet--><servlet><servlet-name>dispatcherServlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!-- 指定配置文件位置和名稱 如果不設置,默認找/WEB-INF/<servlet-name>-servlet.xml --><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:springmvc.xml</param-value></init-param><load-on-startup>1</load-on-startup><async-supported>true</async-supported></servlet><servlet-mapping><servlet-name>dispatcherServlet</servlet-name><url-pattern>/</url-pattern></servlet-mapping><!--Rest風格的URL--><filter><filter-name>HiddenHttpMethodFilter</filter-name><filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class></filter><filter-mapping><filter-name>HiddenHttpMethodFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping>
</web-app>

? ? 3.2、配置spring掃描和注解驅動:spring-mvc.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"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"><!-- 掃描注解,這樣com.sk包下的文件都能被掃描 --><context:component-scan base-package="com.sk"/><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/jsp/"/><property name="suffix" value=".jsp"/></bean><bean class="org.springframework.web.servlet.view.BeanNameViewResolver"><property name="order" value="100"/></bean><!--靜態資源--><mvc:default-servlet-handler/><!--配置注解驅動--><mvc:annotation-driven><mvc:message-converters><bean class="org.springframework.http.converter.StringHttpMessageConverter"><property name="defaultCharset" value="UTF-8"/><property name="writeAcceptCharset" value="false"/></bean><bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/></mvc:message-converters></mvc:annotation-driven><bean id="multipartResolver"class="org.springframework.web.multipart.commons.CommonsMultipartResolver"><property name="defaultEncoding" value="UTF-8"/><property name="maxUploadSize" value="1024000"/></bean>
</beans>

3.3、配置屬性配置和業務層:applicationContext.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"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"><!--數據源--><context:property-placeholder location="classpath:db.properties"/><!-- 數據庫連接池 --><!-- 配置數據源 --><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="driverClassName" value="${jdbc.driver}"/><property name="url" value="${jdbc.url}"/><property name="username" value="${jdbc.user}"/><property name="password" value="${jdbc.password}"/></bean><!-- mybatis和spring完美整合,不需要mybatis的配置映射文件 --><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource"/><!-- 掃描domain包 --><property name="typeAliasesPackage" value="com.david.domain"/><!-- 掃描sql配置文件:mapper需要的xml文件--><property name="mapperLocations" value="classpath:mapper/*.xml"/></bean><!-- Mapper動態代理開發,掃描dao接口包--><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><!-- 注入sqlSessionFactory --><property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/><!-- 給出需要掃描Dao接口包 --><property name="basePackage" value="com.sk.mapper"/></bean><bean id="person" class="com.sk.domain.User" scope="prototype" abstract="false"/>
</beans>

4、啟動方式:手動編寫啟動類,兩種啟動方式

? ? 4.1、方式一 :web.xml配置以下xml內容? ?

<context-param>                <!--Spring上下文配置--><param-name>contextConfigLocation</param-name>              <param-value>/WEB-INF/rootContext.xml</param-value>        <!--指定配置文件地址及文件名稱-->
</context-param>
<listener>         <!--上下文初始化監聽器--><listener-class>org.springframework.web.context.ContextloadListener</listener-class>
</listener><servlet>        <!--配置Servlet--><servlet-name>springDispatcher</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/servletContext.xml</param-value></init-param><load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping><servlet-name>springDispatcher</servlet-name><url-pattern>/</url-pattern>
</servlet-mapping>

? ? 4.2、方式二?? ?

public class Bootstrap implements WebApplicationInitializer{@overvidepublic void onStartup(ServletContext container){XmlWebApplicationContext rootContext = new XmlWebApplicationContext();rootContext.setConfigLocation("/WEB-INF/rootContext.xml");container.addListener(new ContextLoaderListerner(rootContext));XmlWebApplicationContex servletContext = new XmlWebApplicationContex();servletCOntext.setConfigLocation("/WEB-INF/servletContext.xml");ServletRegistration.Dynamic dispatcher = container.addServlet("springDispatcher", new DispatcherServlet(servletContext));dispatcher.setLoadOnStartup(1);dispatcher.addMapping("/");}
}

二、History of Spring Boot

?? ?Spring Boot aims to make it easy to create Spring-powered, production-grade applications and services with minimum fuss. It takes an opinionated view of the Spring platform so that new and existing users can quickly get to the bits they need. You can use it to create stand-alone Java applications that can be started using?'java -jar'?or more traditional WAR deployments. We also provide a command line tool that runs 'spring scripts'.

The diagram below shows Spring Boot as a point of focus on the larger Spring ecosystem. It presents a small surface area for users to approach and extract value from the rest of Spring:

?? ??? ?

The primary goals of Spring Boot are:

  • To provide a radically faster and widely accessible 'getting started' experience for all Spring development

  • To be opinionated out of the box, but get out of the way quickly as requirements start to diverge from the defaults

  • To provide a range of non-functional features that are common to large classes of projects (e.g. embedded servers, security, metrics, health checks, externalized configuration)

Spring Boot does?not?generate code and there is absolutely?no?requirement for XML configuration.

?Spring Boot快速開發框架,開箱即用,不生產任何代碼,也不需要XML配置。解決Sping Framework不一致配置和web容器問題

舉例:spring boot +?spring mvc + mybatis

1、應用場景:快速開發框架,開箱即用,簡化開發、部署、運行過程?? ?

2、依賴配置:自動添加所需依賴?? ?

 <groupId>com.jack</groupId><artifactId>springboot-mybatis</artifactId><version>0.0.1-SNAPSHOT</version><name>springboot-mybatis</name><description>Demo project for Spring Boot</description><properties><java.version>8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>1.3.1</version></dependency></dependencies>

3、配置管理:使用application配置

? ? 只有application.properties或者application.yml

4、啟動方式: @SpringBootApplication注解來自動配置和啟動Spring應用程序?? ?

@SpringBootApplication
@ComponentScan(basePackages={"com.sk"})
public class SpringbootMybatisApplication {public static void main(String[] args) {SpringApplication.run(SpringbootMybatisApplication.class, args);}
}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/13974.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/13974.shtml
英文地址,請注明出處:http://en.pswp.cn/web/13974.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

nginx 配置stream模塊代理并開啟日志配置

前言 nginx 1.20.1 nginx從1.9.0開始,新增加了一個stream模塊 確保nginx 安裝時開啟stream模塊 ./configure \ …… \ --with-stream \ --with-stream_ssl_module \ 修改nginx.conf #增加stream配置&#xff0c;開啟stream模塊 stream {log_format basic $remote_addr [$…

stm32 作為從機, fpga 作為主機,進行 spi 通信

stm32 作為從機, fpga 作為主機,進行 spi 通信 STM32和FPGA之間的SPI通信是直連形式。使用FPGA讀取傳感器的值,傳輸到STM32中進行計算。 STM32是將SPI接受過來的數據存儲到DMA中。 #include "SPI_DMA.h" #include <stm32f10x.h> uint8_t spi_buf[4];//FP…

idea啟動報錯:java.lang.NoClassDefFoundError: org/mybatis/logging/LoggerFactory

文章目錄 一、問題二、解決方法 一、問題 問題描述&#xff1a;idea整合Mybatis-plus的時候&#xff0c;啟動報錯&#xff1a;java.lang.NoClassDefFoundError: org/mybatis/logging/LoggerFactory 二、解決方法 可能原因&#xff1a;仔細檢查了一下&#xff0c;發現 mybati…

《王者榮耀》4月狂攬2.34億美元 單日流水1億美元 全球銷量第二

易采游戲網5月24日消息&#xff0c;在剛剛過去的四月&#xff0c;全球手游市場迎來了一場收益的盛宴&#xff0c;其中《王者榮耀》以其驚人的吸金能力&#xff0c;以2.34億美元的月收入在全球手游排行榜上位列第二。4月5日&#xff0c;這款由騰訊游戲開發的多人在線戰斗競技游戲…

C++相關概念和易錯語法(14)(初始化注意事項、vector、編譯器向上查找規則)

1.當我們在代碼中想要終止運行的話&#xff0c;我們可以采用Ctrl C或Ctrl Z&#xff0c;其中^C代表殺進程&#xff0c;^Z設置結束2.編碼表&#xff1a;我們目前比較熟悉的是ASCII碼編碼方式&#xff0c;但是我們發現平時使用的漢字無法通過ASCII編碼&#xff0c;除此之外&…

前端canvas項目實戰——在線圖文編輯器:序

目錄 前言一、 博主是誰&#xff1f;二、 關于本專欄1. 本專欄涉及的技術棧2. 專欄適合誰來學習&#xff1f;3. 你可以從專欄學到什么&#xff1f;4. 系列文章索引 三、 付費信息后記 前言 很高興&#xff0c;今天我又為自己設定了一個目標&#xff1a;帶領大家從入門HTML5中的…

自動化測試用例結構

標準的用例結構&#xff1a; 用力標題前提條件用例步驟預期結果實際結果 測試用例對比&#xff1a;

酷開系統 | 酷開科技把握智慧先機 AI賦能家庭場景

智慧化是當今世界科技發展的前沿領域之一。現在的智慧化&#xff0c;也正在逐步成為我們日常生活的一部分。電視系統也進入了數字化時代&#xff0c;AI的應用正在不斷擴展&#xff0c;其潛力似乎無窮無盡。 酷開科技深耕人工智能技術&#xff0c;在提升語音體驗、強化智能家居…

(1)無線電失控保護(二)

文章目錄 前言 4 參數配置 5 測試 6 使用接收器設置飛行模式(

第二證券:新股申購配號數什么意思?

股配號數量便是我們參與抽簽的數量&#xff0c;投資者申購新股之后&#xff0c;交易所會根據持有的股票市值進行配號。 投資者的市值越大&#xff0c;申購新股的配號越多&#xff0c;其中簽機會越大。主板、創業板、科創板一個申購單位是500股&#xff0c;意味著1萬元的市值有…

Scrapy 從創建到運行

Scrapy是一個強大的Python框架&#xff0c;專門用于構建網絡爬蟲。 步驟1&#xff1a;安裝Scrapy 首先&#xff0c;你需要安裝Scrapy框架來進行后續操作。以下是具體操作步驟&#xff1a; 1、使用pip命令安裝Scrapy&#xff1a; pip install scrapy 步驟2&#xff1a;創建S…

Java 定義類型處理MySQL point類型數據

1.三個類來處理 引入maven依賴 <!-- 引入 jts 庫解析 POINT --><dependency><groupId>com.vividsolutions</groupId><artifactId>jts</artifactId><version>1.13</version></dependency>import javax.validation.constr…

MySQL的數據類型之文本類型

目錄 文本類型類型&#xff1a; CHAR(size) VARCHAR(size) TEXT TINYTEXT, MEDIUMTEXT, LONGTEXT BLOB, MEDIUMBLOB, LONGBLOB ENUM 在mysql中&#xff0c;常用數據類型有三種&#xff1a; 1、文本類型&#xff1b; 2、數字類型&#xff1b; 3、日期/時間類型&#xff1b; …

【C++入門】—— C++入門 (下)_內聯函數

前言&#xff1a;在了解完前面的C基礎內容后&#xff0c;馬上我們就要真正不如C的學習了&#xff0c;但在之前讓我們最后了解最后一點點C入門知識&#xff01;來遲的520特別篇&#xff01; 本篇主要內容&#xff1a; 內聯函數 auto關鍵字 范圍for 指針空值nullptr C入門 1. 內聯…

星戈瑞CY3-COOH染料的穩定性、熒光特性

CY3-COOH染料&#xff0c;作為一種多功能的熒光標記試劑&#xff0c;在生物醫學研究和熒光成像技術中應用。其穩定性和熒光特性使得它在科研實驗使用。 CY3-COOH染料的穩定性 CY3-COOH染料以其穩定性而應用。首先&#xff0c;它展現出了良好的化學穩定性&#xff0c;不易受到環…

智慧醫療時代:探索互聯網醫院開發的新篇章

在智慧醫療時代&#xff0c;互聯網醫院開發正引領著醫療服務的創新浪潮。通過將先進的技術與醫療服務相結合&#xff0c;互聯網醫院為患者和醫生提供了全新的互動方式&#xff0c;極大地提升了醫療服務的便捷性和效率。本文將深入探討互聯網醫院的開發&#xff0c;介紹其技術實…

一鍵部署!QQ AI 聊天機器人!支持ChatGPT、文心一言、訊飛星火、Bing、Bard、ChatGLM、POE,多賬號,人設調教

隨著人工智能技術的不斷發展&#xff0c;智能聊天機器人已經成為我們日常生活中不可或缺的一部分。ChatGPT作為一款強大的人工智能聊天模型&#xff0c;能夠為我們提供高效、便捷的聊天體驗。那么&#xff0c;如何將ChatGPT接入QQ&#xff0c;實現智能聊天新體驗呢&#xff1f;…

關于Git 的基本概念和使用方式

Git是一個分布式版本控制系統&#xff0c;用于跟蹤和管理代碼的改動。它具有以下基本概念和使用方式&#xff1a; 1. 倉庫&#xff08;Repository&#xff09;&#xff1a;Git使用倉庫來存儲代碼和相關的歷史記錄。倉庫可以是本地的&#xff0c;也可以是遠程的。本地倉庫保存在…

DB2學習筆記--1

一 數據控制語言(DCL) 1.GRANT語句 使用 GRANT 語句可以向單個用戶或組顯式授予權限和特權&#xff0c;授權對象包括數據庫、 表空間、表、視圖、索引、包和模式。 GRANT 的語法如下: GRANT privilege ON object-type object-name TO {USER|GROUP|PUBLIC} authorization-na…

OTP8腳-全自動擦鞋機WTN6020-低成本語音方案

一&#xff0c;產品開發背景 首先&#xff0c;隨著人們生活質量的提升&#xff0c;對鞋子的保養需求也日益增加。鞋子作為人們日常穿著的重要組成部分&#xff0c;其清潔度和外觀狀態直接影響到個人形象和舒適度。因此&#xff0c;一種能夠自動清潔和擦亮鞋子的設備應運而生&am…