Spring註解學習手札(一)構建web應用
網上找了一些個例子,總的說來比較土,大多數是轉載摘抄,按照提示弄下來根本都執行不了,索性自己趟一遍這渾水,在這裡留下些個印記。
這次,先來構建一個極為簡單的web應用,從controller到dao。不考慮具體實現,只是先對整體架構有一個清晰的瞭解。日後在分層細述每一層的細節。
我們將用到如下jar包:
引用
aopalliance-1.0.jar
commons-logging-1.1.1.jar
log4j-1.2.15.jar
spring-beans-2.5.6.jar
spring-context-2.5.6.jar
spring-context-support-2.5.6.jar
spring-core-2.5.6.jar
spring-tx-2.5.6.jar
spring-web-2.5.6.jar
spring-webmvc-2.5.6.jar
先看web.xml
Xml程式碼
- <?xmlversion="1.0"encoding="UTF-8"?>
- <web-app
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
- id="WebApp_ID"
- version="2.5">
- <display-name>spring</display-name>
- <!-- 應用路徑 -->
- <context-param>
- <param-name>webAppRootKey</param-name>
- <param-value>spring.webapp.root</param-value>
- </context-param>
- <!-- Log4J 配置 -->
- <context-param>
- <param-name>log4jConfigLocation</param-name>
- <param-value>classpath:log4j.xml</param-value>
- </context-param>
- <context-param>
- <param-name>log4jRefreshInterval</param-name>
- <param-value>60000</param-value>
- </context-param>
- <!--Spring上下文 配置 -->
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>/WEB-INF/applicationContext.xml</param-value>
- </context-param>
- <!-- 字符集 過濾器 -->
- <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>
- <!-- Spring 監聽器 -->
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <listener>
- <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
- </listener>
- <!-- Spring 分發器 -->
- <servlet>
- <servlet-name>spring</servlet-name>
- <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
- <init-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>/WEB-INF/servlet.xml</param-value>
- </init-param>
- </servlet>
- <servlet-mapping>
- <servlet-name>spring</servlet-name>
- <url-pattern>*.do</url-pattern>
- </servlet-mapping>
- <welcome-file-list>
- <welcome-file>index.html</welcome-file>
- <welcome-file>index.htm</welcome-file>
- <welcome-file>index.jsp</welcome-file>
- <welcome-file>default.html</welcome-file>
- <welcome-file>default.htm</welcome-file>
- <welcome-file>default.jsp</welcome-file>
- </welcome-file-list>
- </web-app>
有不少人問我,這段程式碼是什麼:
Xml程式碼
- <!-- 應用路徑 -->
- <context-param>
- <param-name>webAppRootKey</param-name>
- <param-value>spring.webapp.root</param-value>
- </context-param>
這是當前應用的路徑變數,也就是說你可以在其他程式碼中使用${spring.webapp.root}指代當前應用路徑。我經常用它來設定log的輸出目錄。
為什麼要設定引數log4jConfigLocation?
Xml程式碼
- <!-- Log4J 配置 -->
- <context-param>
- <param-name>log4jConfigLocation</param-name>
- <param-value>classpath:log4j.xml</param-value>
- </context-param>
- <context-param>
- <param-name>log4jRefreshInterval</param-name>
- <param-value>60000</param-value>
- </context-param>
這是一種基本配置,spring中很多程式碼使用了不同的日誌介面,既有log4j也有commons-logging,這裡只是強制轉換為log4j!並且,log4j的配置檔案只能放在classpath根路徑。同時,需要通過commons-logging配置將日誌控制權轉交給log4j。同時commons-logging.properties必須放置在classpath根路徑。
commons-logging內容:
Properties程式碼
- org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
最後,記得配置log4j的監聽器:
Xml程式碼
- <listener>
- <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
- </listener>
接下來,我們需要配置兩套配置檔案,applicationContext.xml和servlet.xml。
applicationContext.xml用於對應用層面做整體控制。按照分層思想,統領service層和dao層。servlet.xml則單純控制controller層。
Xml程式碼
- <?xmlversion="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.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
- <import
- resource="service.xml"/>
- <import
- resource="dao.xml"/>
- </beans>
applicationContext.xml什麼都不幹,它只管涉及到整體需要的配置,並且集中管理。
這裡引入了兩個配置檔案service.xml和dao.xml分別用於業務、資料處理。
service.xml
Xml程式碼
- <?xmlversion="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.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
- <context:component-scan
- base-package="org.zlex.spring.service"/>
- </beans>
注意,這裡通過<context:component-scan />標籤指定了業務層的基礎包路徑——“org.zlex.spring.service”。也就是說,業務層相關實現均在這一層。這是有必要的分層之一。
dao.xml
Xml程式碼
- <?xmlversion="1.0"encoding="UTF-8"?>
- <beans
- xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
- <context:component-scan
- base-package="org.zlex.spring.dao"/>
- </beans>
dao層如法炮製,包路徑是"org.zlex.spring.dao"。從這個角度看,註解還是很方便的!
最後,我們看看servlet.xml
Xml程式碼
- <?xmlversion="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.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
- <context:component-scan
- base-package="org.zlex.spring.controller"/>
- <bean
- id="urlMapping"
- class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
- <bean
- class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
- </beans>
包路徑配置就不細說了,都是一個概念。最重要的時候後面兩個配置,這將使得註解生效!
“org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping”是預設實現,可以不寫,Spring容器預設會預設使用該類。
“org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter”直接關係到多動作控制器配置是否可用!
簡單看一下程式碼結構,如圖:
Account類是來儲存賬戶資訊,屬於域物件,極為簡單,程式碼如下所示:
Account.java
Java程式碼
- /**
- * 2010-1-23
- */
- package org.zlex.spring.domain;
- import java.io.Serializable;
- /**
- *
- * @author <a href="mailto:[email protected]">樑棟</a>
- * @version 1.0
- * @since 1.0
- */
- publicclass Account implements Serializable {
- /**
- *
- */
- privatestaticfinallong serialVersionUID = -533698031946372178L;
- private String username;
- private String password;
- /**
- * @param username
- * @param password
- */
- public Account(String username, String password) {
- this.username = username;
- this.password = password;
- }
- /**
- * @return the username
- */
- public String getUsername() {
- return username;
- }
- /**
- * @param username the username to set
- */
- publicvoid setUsername(String username) {
- this.username = username;
- }
- /**
- * @return the password
- */
- public String getPassword() {
- return password;
- }
- /**
- * @param password the password to set
- */
- publicvoid setPassword(String password) {
- this.password = password;
- }
- }
通常,在構建域物件時,需要考慮該物件可能需要進行網路傳輸,本地快取,因此建議實現序列化介面Serializable
我們再來看看控制器,這就稍微複雜了一點程式碼如下所示:
AccountController .java
Java程式碼
- /**
- * 2010-1-23
- */
- package org.zlex.spring.controller;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.ServletRequestUtils;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.zlex.spring.service.AccountService;
- /**
- *
- * @author <a href="mailto:[email protected]">樑棟</a>
- * @version 1.0
- * @since 1.0
- */
- @Controller
- @RequestMapping("/account.do")
- publicclass AccountController {
- @Autowired
- private AccountService accountService;
- @RequestMapping(method = RequestMethod.GET)
- publicvoid hello(HttpServletRequest request, HttpServletResponse response)
- throws Exception {
- String username = ServletRequestUtils.getRequiredStringParameter(
- request, "username");
- String password = ServletRequestUtils.getRequiredStringParameter(
- request, "password");
- System.out.println(accountService.verify(username, password));
- }
- }
分段詳述:
Java程式碼
- @Controller
- @RequestMapping("/account.do")
這兩行註解,@Controller是告訴Spring容器,這是一個控制器類,@RequestMapping("/account.do")是來定義該控制器對應的請求路徑(/account.do)
Java程式碼
- @Autowired
- private AccountService accountService;
這是用來自動織入業務層實現AccountService,有了這個註解,我們就可以不用寫setAccountService()方法了!
同時,JSR-250標準註解,推薦使用@Resource來代替Spring專有的@Autowired註解。
引用 Spring 不但支援自己定義的@Autowired註解,還支援幾個由JSR-250規範定義的註解,它們分別是@Resource、@PostConstruct以及@PreDestroy。
@Resource的作用相當於@Autowired,只不過@Autowired按byType自動注入,而@Resource預設按 byName自動注入罷了。@Resource有兩個屬性是比較重要的,分別是name和type,Spring將@Resource註解的name屬性解析為bean的名字,而type屬性則解析為bean的型別。所以如果使用name屬性,則使用byName的自動注入策略,而使用type屬性時則使用byType自動注入策略。如果既不指定name也不指定type屬性,這時將通過反射機制使用byName自動注入策略。
@Resource裝配順序
1. 如果同時指定了name和type,則從Spring上下文中找到唯一匹配的bean進行裝配,找不到則丟擲異常
2. 如果指定了name,則從上下文中查詢名稱(id)匹配的bean進行裝配,找不到則丟擲異常
3. 如果指定了type,則從上下文中找到型別匹配的唯一bean進行裝配,找不到或者找到多個,都會丟擲異常
4. 如果既沒有指定name,又沒有指定type,則自動按照byName方式進行裝配(見2);如果沒有匹配,則回退為一個原始型別(UserDao)進行匹配,如果匹配則自動裝配;
1.6. @PostConstruct(JSR-250)
在方法上加上註解@PostConstruct,這個方法就會在Bean初始化之後被Spring容器執行(注:Bean初始化包括,例項化Bean,並裝配Bean的屬性(依賴注入))。
這有點像ORM最終被JPA一統天下的意思! 大家知道就可以了,具體使用何種標準由專案說了算!
最後,來看看核心方法:
Java程式碼
- @RequestMapping(method = RequestMethod.GET)
- publicvoid hello(HttpServletRequest request, HttpServletResponse response)
- throws Exception {
- String username = ServletRequestUtils.getRequiredStringParameter(
- request, "username");
- String password = ServletRequestUtils.getRequiredStringParameter(
- request, "password");
- System.out.println(accountService.verify(username, password));
- }
註解@RequestMapping(method = RequestMethod.GET)指定了訪問方法型別。
注意,如果沒有用這個註解標識方法,Spring容器將不知道那個方法可以用於處理get請求!
對於方法名,我們可以隨意定!方法中的引數,類似於“HttpServletRequest request, HttpServletResponse response”,只要你需要方法可以是有參也可以是無參!
解析來看Service層,分為介面和實現:
AccountService.java
Java程式碼
- /**
- * 2010-1-23
- */
- package org.zlex.spring.service;
- /**
- *
- * @author <a href="mailto:[email protected]">樑棟</a>
- * @version 1.0
- * @since 1.0
- */
- publicinterface AccountService {
- /**
- * 驗證使用者身份
- *
- * @param username
- * @param password
- * @return
- */
- boolean verify(String username, String password);
- }
介面不需要任何Spring註解相關的東西,它就是一個簡單的介面!
重要的部分在於實現層,如下所示:
AccountServiceImpl.java
Java程式碼
- /**
- * 2010-1-23
- */
- package org.zlex.spring.service.impl;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import org.zlex.spring.dao.AccountDao;
- import org.zlex.spring.domain.Account;
- import org.zlex.spring.service.AccountService;
- /**
- *
- * @author <a href="mailto:[email protected]">樑棟</a>
- * @version 1.0
- * @since 1.0
- */
- @Service
- @Transactional
- publicclass AccountServiceImpl implements AccountService {
- @Autowired
- private AccountDao accountDao;
- /*
- * (non-Javadoc)
- *
- * @see org.zlex.spring.service.AccountService#verify(java.lang.String,
- * java.lang.String)
- */
- @Override
- publicboolean verify(String username, String password) {
- Account account = accountDao.read(username);
- if (password.equals(account.getPassword())) {
- returntrue;
- } else {
- returnfalse;
- }
- }
- }
注意以下內容:
Java程式碼
- @Service
- @Transactional
註解@Service用於標識這是一個Service層實現,@Transactional用於控制事務,將事務定位在業務層,這是非常務實的做法!
接下來,我們來看持久層:AccountDao和AccountDaoImpl類
AccountDao.java
Java程式碼
- /**
- * 2010-1-23
- */
- package org.zlex.spring.dao;
- import org.zlex.spring.domain.Account;
- /**
- *
- * @author <a href="mailto:[email protected]">樑棟</a>
- * @version 1.0
- * @since 1.0
- */
- publicinterface AccountDao {
- /**
- * 讀取使用者資訊
- *
- * @param username
- * @return
- */
- Account read(String username);
- }
這個介面就是簡單的資料提取,無需任何Spring註解有關的東西!
再看其實現類:
AccountDaoImpl.java
Java程式碼
- /**
- * 2010-1-23
- */
- package org.zlex.spring.dao.impl;
- import org.springframework.stereotype.Repository;
- import org.zlex.spring.dao.AccountDao;
- import org.zlex.spring.domain.Account;
- /**
- *
- * @author <a href="mailto:[email protected]">樑棟</a>
- * @version 1.0
- * @since 1.0
- */
- @Repository
- publicclass AccountDaoImpl implements AccountDao {
- /* (non-Javadoc)
- * @see org.zlex.spring.dao.AccountDao#read(java.lang.String)
- */
- @Override
- public Account read(String username) {
- returnnew Account(username,"wolf");
- }
- }
這裡只需要注意註解:
Java程式碼
- @Repository
意為持久層,Dao實現這層我沒有過於細緻的介紹通過註解呼叫ORM或是JDBC來完成實現,這些內容後續細述!
這裡我們沒有提到註解@Component,共有4種“元件”式註解:
引用
@Component:可裝載元件
@Repository:持久層元件
@Service:服務層元件
@Controller:控制層元件
這樣spring容器就完成了控制層、業務層和持久層的構建。
啟動應用,訪問http://localhost:8080/spring/account.do?username=snow&password=wolf
觀察控制檯,如果得到包含“true”的輸出,本次構建就成功了!
程式碼見附件!
順便說一句:在Spring之前的XML配置中,如果你想在一個類中獲得檔案可以通過在xml配置這個類的某個屬性。在註解的方式(Spring3.0)中,你可以使用@Value來指定這個檔案。
例如,我們想要在一個類中獲得一個檔案,可以這樣寫:
Java程式碼
- @Value("/WEB-INF/database.properties")
- private File databaseConfig;
如果這個properties檔案已經正常在容器中載入,可以直接這樣寫:
Java程式碼
- @Value("${jdbc.url}")
- private String url;
獲得這個url引數!
容器中載入這個Properties檔案:
Xml程式碼
- <util:propertiesid="jdbc"location="/WEB-INF/database.properties"/>
這樣,我們就能通過註解@Value獲得/WEB-INF/database.properties這個檔案!
如果我們想要獲得注入在xml中的某個類,例如dataSource(<bean id ="dataSource">)可以在註解的類中這麼寫:
Java程式碼
- @Resource(name = "dataSource")
- private BasicDataSource dataSource;
如果只有這麼一個類使用該配置檔案:
Java程式碼
- @ImportResource("/WEB-INF/database.properties")
- publicclass AccountDaoImpl extends AccountDao {
就這麼簡單!
相關推薦
Spring註解學習手札(一)構建web應用
近來工作發生了一些變化,有必要學習一下Spring註解了! 網上找了一些個例子,總的說來比較土,大多數是轉載摘抄,按照提示弄下來根本都執行不了,索性自己趟一遍這渾水,在這裡留下些個印記。 這次,先來構建一個極為簡單的web應用,從controller到dao。不考慮具體實現
Spring 註解學習手札(一) 構建簡單Web應用
轉載自 http://snowolf.iteye.com/blog/577989 我們將用到如下jar包: 引用 aopalliance-1.0.jar commons-logging-1.1.1.jar log4j-1.2.15.ja
Spring 註解學習手札(四) 持久層淺析
這裡將用到以下幾個包: 引用 aopalliance-1.0.jar commons-collections.jar commons-dbcp.jar commons-logging-1.1.1.jar commons-pool.jar jstl.jar log4j-1.
Spring 註解學習手札(八)補遺——@ExceptionHandler
Spring註解,改變了我的開發思路。前段時間,用@RequestBody,@ResponseBody,不費吹灰之力就解決了JSon自動繫結。接著就發現,如果遇到RuntimeException,需要給出一個預設返回JSON。 以前都是用SimpleMappingExcep
Spring學習手札(一)
Spring能做什麼 1. 能根據配置檔案建立及組裝物件之間的依賴關係; 2. 面向切面程式設計,能幫助我們無耦合的實現日誌記錄,效能統計,安全控制等; 3. 提供第三方資料訪問框架(如Hibernate),而且自己也提供了一套JDBC訪問模板方便訪問資料庫; 4. 非常簡單的管理資料庫事務;
Spring Boot學習筆記(一)——專案構建-使用-部署
Spring Boot簡介很榮幸剛開始學習java框架就接觸到了spring boot,並得到大神的指點,通過查閱資料以及教程學會在實際專案中去使用它,相對於其他框架只有一個字來形容 - “爽”。最近也
spring boot學習系列(一)
web服務器 應用程序 spring 控制器 做什麽 spring boot開發第一個應用程序1、spring boot是什麽?2、spring boot容易上手嗎?寫這篇文章技術文章,主要是記錄日常的學習以及理解。我們重新認識一下spring假設你受命使用spring開發一個簡單的hel
1、spring-boot學習筆記(一)簡單入門
ava project nal run plugin mailto 5.4 安全 class a 一、新建普通Maven工程 pom.xml <parent> <groupId>org.springframework.boot</gr
Spring Boot 學習筆記(一)—— 快速搭建Spring Boot專案
一、前言 Spring Boot是Spring系列框架的整合,使用“習慣優於配置”的理念快速搭建專案,在專案打包時還能根據需求打包為jar(內建servlet容器)或war檔案,相對以前的Spring、Spring MVC來說Spring Boot並沒有技術上的升級,而是為我們做好了大部
Spring AOP學習筆記(一):基礎概念
AOP產生背景 AOP(Aspect Oriented Programming),即面向切面程式設計,可以說是OOP(Object Oriented Programming,面向物件程式設計)的補充和完善。OOP引入封裝、繼承、多型等概念來建立一種物件層次結構,用於模擬公共行為的一個集合。不
Spring Boot 學習總結 (一)---入口類和@SpringBootApplication
入口類和@SpringBootApplication SpringBoot通常有一個名為*Application的入口類,入口類裡有一個main方法,這個main方法是一個標準的java應用的入口方法。在main方法中使用SpringApplication.run(*App
Spring原始碼學習筆記 (一)bean是怎麼生成的
bean 實在 bean 重新整理過程中產生的,首先我們看下 bean 的重新整理方法。下面是 AbstractApplicationContext 的 refresh 方法。 @Override public void refresh() throws
Spring Boot學習實踐(一)(1)建立一個簡單的spring boot應用
一、使用idea建立一個簡單的Spring Boot應用程式 環境準備: idea:2018.2 jdk: 1.8 spring boot:是2.0版本以上的 以上環境可以根據實際情況去調整。 (1)首先找到idea建立應用的New Project,選擇好
SpringCloud學習心得(一) 構建最基礎的SpringCloud專案
首先本系列部落格參照 史上最簡單的 SpringCloud 教程,地址:https://blog.csdn.net/forezp/article/details/70148833根據工作需要,筆者最近研究SpringCloud微服務框架,將最近的學習過程寫下來供大家參考。好,
Spring Boot學習日誌(一)Hello World
目錄 一,系統環境 JDK:1.8.0_144 maven:3.5.2 二,使用IntelliJ IDEA建立專案 1,選擇專案型別 2,編輯專案資訊 這裡packaging可以選擇jar 或者 war 3,選擇需要的war包
Spring MVC學習記錄(一)——網站基礎知識(1)
Spring MVC學習之——網路架構及演變過程 1.軟體的三大型別:單機型別、CS型別、BS型別。 單機型別:曾經的主要軟體型別,不聯網,實現電腦的基本功能,如打字、畫圖。 CS型別:單機之後為了統一管理軟體的資料,產生了客戶端和伺服器端,客戶端管理業務,伺服器端管理資料
Spring Boot 學習筆記(一)入門
Spring boot 簡介 1、Spring boot是Spring家族中的一個全新的框架,它用來簡化Spring應用程式的建立和開發過程,也可以說Spring boot能簡化我們之前採用Spring mvc + Spring + MyBatis 框架進行開發的過程; 2、在以往我們採用 Spring
Spring Cloud 學習筆記(一)——入門、特徵、配置
目錄 0 放在前面 0.1 參考文件 http://cloud.spring.io/spring-cloud-static/Brixton.SR7/ https://springcloud.cc/ http://projects.spring.io/spring-cloud/ 0.2 maven配置 &
Spring註解驅動開發(一)
[email protected]註解 這個相當於配置檔案,即告訴spring這個一個配置類。 [email protected] 給容器註冊一個Bean;型別為返回值的型別,id預設是用方法名作為id. @Configurat
spring boot 學習筆錄(一)
(1)、spring Framework(Core):spring專案的核心。Spring Framework中包含了一系列的IoC容器的設計,提供了依賴反轉模式的實現。同時,還集成了AOP功能,包含了其他Spring的基本模組,如MVC,JDBC,事務處理模組的實現。 (2)、spring Web Flo