SpringMVC實(shí)現(xiàn)文件上傳和下載的工具類
本文主要目的是記錄自己基于SpringMVC實(shí)現(xiàn)的文件上傳和下載的工具類的編寫,代碼經(jīng)過測(cè)試可以直接運(yùn)行在以后的項(xiàng)目中。
開發(fā)的主要思路是對(duì)上傳和下載文件進(jìn)行抽象,把上傳和下載的核心功能抽取出來分裝成類。
我的工具類具體代碼如下:
package com.baosight.utils; import java.io.BufferedInputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Properties; import org.apache.commons.fileupload.util.Streams; import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.multipart.MultipartFile; /** * springMVC中文件的工具類 * * @author chenpeng * */ public class MyfileUtils { private static final Logger logger = LoggerFactory.getLogger(MyfileUtils.class); /** * 存儲(chǔ)的路徑,默認(rèn)的為c盤符 */ public static String directory = "c:/"; /** * 圖片的大小配置,默認(rèn)為2048000 */ public static long imagesize = 2048000; /** * 圖片的類型配置默認(rèn)如下 */ public static String imagetype = "image/bmp,image/png,image/jpeg,image/jpg"; /** * 文件上傳的大小限制 */ public static long filesize = 20971520; /** * 文件上傳文件的類型 */ public static String filetype = "application/msword,application/pdf,application/zip,video/mpeg,video/quicktime,video/x-sgi-movie,video/mpeg,video/x-msvideo,audio/x-mpeg,application/octet-stream"; /** * 配置路徑的字段 */ public static final String DIRECTORY = "myfileutils.uploadFileDirectory"; /** * 配置圖片大小的字段 */ public static final String IMAGESIZE = "myfileutils.imgSize"; /** * 配置圖片類型的字段 */ public static final String IMAGETYPE = "myfileutils.imgType"; /** * 文件的大小 */ public static final String FILESIZE = "myfileutils.fileSize"; /** * 文件的類型 */ public static final String FILETYPE = "myfileutils.fileType"; /** * 文件所支持的全部類型(圖片,office文件,壓縮包,視頻,音頻) */ public static String[] sporting_filetype; /** * 上傳的結(jié)果 * * @author cp UPLOAD_SUCCESS:"上傳成功" UPLOAD_SIZE_ERROR:"上傳文件過大" * UPLOAD_TYPE_ERROR:"上傳文件類型錯(cuò)誤" UPLOAD_FILE:"上傳文件失敗" * */ public static enum Upload { UPLOAD_SUCCESS("上傳成功", 1), UPLOAD_SIZE_ERROR("上傳文件過大", 2), UPLOAD_TYPE_ERROR("上傳文件類型錯(cuò)誤", 3), UPLOAD_FILE("上傳文件失敗", 4),FILE_DOWNLOAD_SUCCESS("文件下載成功",5),FILE_NOTFOUND("未找到該文件",6); // 成員變量 private String name; @SuppressWarnings("unused") private int index; // 構(gòu)造方法 private Upload(String name, int index) { this.name = name; this.index = index; } // 覆蓋toString方法 @Override public String toString() { return this.name; } } /** * static語句塊讀取配置文件 */ static { Properties properties = new Properties(); try { InputStream in = new BufferedInputStream(MyfileUtils.class.getResourceAsStream("/user-setting.properties")); properties.load(in); Iterator<String> it = properties.stringPropertyNames().iterator(); while (it.hasNext()) { String key = it.next(); String value = properties.getProperty(key); logger.info("讀取配置文件..." + key + ":" + value); switch (key) { // 如果是路徑 case DIRECTORY: // 判斷是否存在該文件夾如果沒有則要重新創(chuàng)建 File file = new File(value); if (!file.exists() && !file.isDirectory()) { // 創(chuàng)建文件夾 file.mkdirs(); } directory = value; break; // 如果是圖片的格式 case IMAGETYPE: imagetype = value; break; // 如果是圖片的大小 case IMAGESIZE: imagesize = Long.parseLong(value); break; // 如果是文件的大小 case FILESIZE: filesize = Long.parseLong(value); break; // 如果是文件的類型 case FILETYPE: filetype = value; break; default: break; } } // 讀取配置后把支持圖片的和支持文件的放在一起 String[] imagetypes = imagetype.split(","); String[] filetypees = filetype.split(","); sporting_filetype = new String[imagetypes.length+filetypees.length]; System.arraycopy(imagetypes, 0, sporting_filetype, 0, imagetypes.length); System.arraycopy(filetypees, 0, sporting_filetype, imagetypes.length, filetypees.length); } catch (FileNotFoundException e) { logger.error("未發(fā)現(xiàn)配置文件"); } catch (IOException e) { logger.error("讀取配置文件失敗"); } } /** * 上傳文件 * * @param multipartFiles * 上傳的文件 * @param parentDir * 上傳文件制定的父文件夾,格式為A/b,可以為空 * @param storageFileName * 上傳的文件的別名,注意上傳文件名不用帶后綴 * @return */ public static List<String> uploadFile(MultipartFile[] multipartFiles, String parentDir, String storageFileName) { List<String> myStrings = new ArrayList<>(); if (multipartFiles != null && multipartFiles.length > 0) { String laString = ""; String storagePath = ""; // 先判斷要存儲(chǔ)的文件夾是否存在,如果不存在就重新創(chuàng)建 String path = directory + ((parentDir!=null)?("/" + parentDir):""); File fileDir = new File(path); if (!fileDir.exists() && !fileDir.isDirectory()) { fileDir.mkdirs(); } for (MultipartFile file : multipartFiles) { // 先判斷文件的類型是否符合配置要求 if (MyfileUtils.checkFileType(file, sporting_filetype)) { /***** 判斷文件的大小 *****/ String type = file.getContentType().substring(0, file.getContentType().lastIndexOf("/")); // 如果是圖片,且大小超過范圍的,如果是文件,且大小超過范圍的直接返回 if ((type.equals("image") && !MyfileUtils.checkFileSize(file, MyfileUtils.imagesize)) || (!type.equals("image") && !MyfileUtils.checkFileSize(file, filesize))) { logger.info("文件過大"); } // 獲取變量名file,文件類型,文件名 logger.info( "上傳的文件:" + file.getName() + "," + file.getContentType() + "," + file.getOriginalFilename()); laString = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); try { if (!file.isEmpty()) { // 判斷sotrageName是否為空,如果不為空就以存儲(chǔ)的命名,為空就以原來的名稱命名 storagePath = path + "/" + ((storageFileName != null) ? (storageFileName + laString) : file.getOriginalFilename()); logger.info("保存的路徑為:" + storagePath); Streams.copy(file.getInputStream(), new FileOutputStream(storagePath), true); myStrings.add(storagePath); } } catch (Exception e) { logger.error("上傳文件失敗"); e.printStackTrace(); } } else { logger.info("上傳文件類型有誤"); } } logger.info("上傳文件成功"); } else { logger.info("上傳文件失 敗"); } return myStrings; } /** * 下載文件 * * @param filePath * 文件的路徑 * @param fileReName * 文件的下載顯示的別名 * @return 文件的對(duì)象 * @throws IOException */ public static ResponseEntity<byte[]> downloadFile(String filePath, String fileReName) throws IOException { // 指定文件,必須是絕對(duì)路徑 File file = new File(filePath); // 下載瀏覽器響應(yīng)的那個(gè)文件名 String dfileName = new String(fileReName.getBytes("GBK"), "iso-8859-1"); // 下面開始設(shè)置HttpHeaders,使得瀏覽器響應(yīng)下載 HttpHeaders headers = new HttpHeaders(); // 設(shè)置響應(yīng)方式 headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); // 設(shè)置響應(yīng)文件 headers.setContentDispositionFormData("attachment", dfileName); // 把文件以二進(jìn)制形式寫回 ResponseEntity<byte[]> result = null; try { result = new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), headers, HttpStatus.CREATED); } catch (Exception e) { logger.error(e.toString()); } return result; } /** * 檢查文件的格式 * * @return */ public static boolean checkFileType(MultipartFile file, String[] supprtedTypes) { String fileType = file.getContentType(); logger.info("文件的格式為:"+fileType); return Arrays.asList(supprtedTypes).contains(fileType); } /** * 判斷文件的大小是否符合要求 * * @param maxSize * 最大文件 * @return */ public static boolean checkFileSize(MultipartFile file, long maxSize) { logger.info("文件的大小比較:"+file.getSize()+",max:"+maxSize); return file.getSize() <= maxSize; } }
需要注意的是我的工具類使用了如下的配置,對(duì)自己的業(yè)務(wù)需求進(jìn)行可配置,提高代碼的應(yīng)用場(chǎng)景(user-setting.properties):
# 上傳文件的父目錄 # 示例:myfileutils.uploadFileDirectory= e:/emp myfileutils.uploadFileDirectory= D:/MyFILES # 上傳圖片的大小 # 示例: myfileutils.imgSize= 2097152 myfileutils.imgSize= 2097152 # 上傳圖片的格式 # 示例:myfileutils.imgType= image/bmp,image/png,image/jpeg,image/jpg,image/x-png,image/pjpeg myfileutils.imgType= image/bmp,image/png,image/jpeg,image/jpg,image/x-png,image/pjpeg # 上傳文件的大小(除了圖片) # 示例:myfileutils.fileSize= 20971520 myfileutils.fileSize= 20971520 # 上傳文件的類型(除了圖片) # 示例:myfileutils.fileType= application/msword,application/pdf,application/zip,video/mpeg,video/quicktime,video/x-sgi-movie,video/mpeg,video/x-msvideo,audio/x-mpeg,application/octet-stream myfileutils.fileType= video/avi,application/vnd.ms-powerpoint,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/msword,application/pdf,application/zip,video/mpeg,video/quicktime,video/x-sgi-movie,video/mpeg,video/x-msvideo,audio/x-mpeg,application/octet-stream
另外本工具類中為了方便調(diào)試錯(cuò)誤與log4j進(jìn)行了集成,所以還需要如下的配置文件:
#定義LOG輸出級(jí)別 log4j.rootLogger=INFO,Console,File #定義日志輸出目的地為控制臺(tái) log4j.appender.Console=org.apache.log4j.ConsoleAppender log4j.appender.Console.Target=System.out #可以靈活地指定日志輸出格式,下面一行是指定具體的格式 log4j.appender.Console.layout = org.apache.log4j.PatternLayout log4j.appender.Console.layout.ConversionPattern=[%c] - %m%n #文件大小到達(dá)指定尺寸的時(shí)候產(chǎn)生一個(gè)新的文件 log4j.appender.File = org.apache.log4j.RollingFileAppender #指定輸出目錄 log4j.appender.File.File = logs/ssm.log #定義文件最大大小 log4j.appender.File.MaxFileSize = 10MB # 輸出所以日志,如果換成DEBUG表示輸出DEBUG以上級(jí)別日志 log4j.appender.File.Threshold = ALL log4j.appender.File.layout = org.apache.log4j.PatternLayout log4j.appender.File.layout.ConversionPattern =[%p] [%d{yyyy-MM-dd HH\:mm\:ss}][%c]%m%n log4j.logger.com.ibatis=DEBUG log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUG log4j.logger.com.ibatis.common.jdbc.ScriptRunner=DEBUG log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG log4j.logger.java.sql.Connection=DEBUG log4j.logger.java.sql.Statement=DEBUG log4j.logger.java.sql.PreparedStatement=DEBUG
下面就開始來重新創(chuàng)建一個(gè)maven的web項(xiàng)目來測(cè)試使用下我的工具類:
1.我使用的開發(fā)工具為idea,新建一個(gè)maven web的項(xiàng)目,然后打開pom.xml配置文件。首先來搭建一下springMVC的開發(fā)環(huán)境,需要引用相關(guān)的jar包,maven的配置文件如下:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.baosight</groupId> <artifactId>testfile</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <name>testfile Maven Webapp</name> <url>http://www.example.com</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> <!-- spring版本號(hào) --> <spring.version>4.0.5.RELEASE</spring.version> <!-- log4j日志文件管理包版本 --> <slf4j.version>1.7.7</slf4j.version> <log4j.version>1.2.17</log4j.version> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <!-- spring核心包 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-oxm</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>${spring.version}</version> </dependency> <!-- 上傳組件包 --> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.3.1</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.2</version> </dependency> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>1.9</version> </dependency> <!--日志包--> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${slf4j.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <!-- 導(dǎo)入java ee jar 包 --> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <scope>provided</scope> <version>7.0</version> </dependency> </dependencies> <build> <finalName>testfile</finalName> <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <plugins> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>3.0.0</version> </plugin> <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.7.0</version> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.20.1</version> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>3.2.0</version> </plugin> <plugin> <artifactId>maven-install-plugin</artifactId> <version>2.5.2</version> </plugin> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.2</version> </plugin> </plugins> </pluginManagement> </build> </project>
配置好pom,然后就來對(duì)springMVC進(jìn)行相關(guān)的配置,首先按照如下的格式創(chuàng)建好對(duì)應(yīng)的文件,里面的配置一一來說明:
1.首先是log4j.properties見上面的配置即可,拷貝到里面并保存;
2.然后是springMVC的配置:
<?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" 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-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!-- 自動(dòng)掃描該包,使SpringMVC認(rèn)為包下用了@controller注解的類是控制器 --> <context:component-scan base-package="com.baosight.controller" /> <mvc:annotation-driven/> <!-- 定義跳轉(zhuǎn)的文件的前后綴 ,視圖模式配置 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <!-- 這里的配置我的理解是自動(dòng)給后面action的方法return的字符串加上前綴和后綴,變成一個(gè) 可用的url地址 --> <property name="prefix" value="/WEB-INF/views/" /> <property name="suffix" value=".jsp" /> </bean> <!-- 配置文件上傳,如果沒有使用文件上傳可以不用配置,當(dāng)然如果不配,那么配置文件中也不必引入上傳組件包 --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <!-- 默認(rèn)編碼 --> <property name="defaultEncoding" value="utf-8" /> <!-- 文件大小最大值 --> <property name="maxUploadSize" value="10485760000" /> <!-- 內(nèi)存中的最大值 --> <property name="maxInMemorySize" value="40960" /> </bean> </beans>
具體配置的內(nèi)容包括啟用注解功能,定義springMVC的視圖解析器,定義上傳文件的大小和編碼;
3.其次是user-setting.properties 里面具體內(nèi)容見上面的用戶配置,主要限定了上傳文件的類型和大小的問題;
4.最后是對(duì)web.xml進(jìn)行配置:
<!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> <display-name>Archetype Created Web Application</display-name> <!-- Spring MVC servlet --> <servlet> <servlet-name>SpringMVC</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- 配置Spring MVC servlet的映射地址 --> <servlet-mapping> <servlet-name>SpringMVC</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
具體包括定義spring的分發(fā)器,指定springMVC文件配置的位置,以及servlet映射的地址;
這樣我們的SpringMVC的開發(fā)環(huán)境算是搭建完成了。
2.下面將我們的工具類拷貝到項(xiàng)目中的自己指定的位置:
3.下面開始正式對(duì)我們的工具類進(jìn)行上傳文件和下載文件的測(cè)試了:
1).首先編寫index.jsp頁面:
<%-- Created by IntelliJ IDEA. User: chenpeng Date: 2018/7/21 Time: 17:03 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <form action="/upload" method="post" enctype="multipart/form-data"> <p>選擇文件:<input type="file" name="files"></p> <p><input type="submit" value="提交"></p> </form> </body> </html>
這樣頁面的效果為:
接著我們來編寫springMVC的后臺(tái):
package com.baosight.controller; import com.baosight.utils.MyfileUtils; import org.springframework.context.annotation.Scope; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import java.io.IOException; import java.util.List; @Controller @Scope("prototype") @RequestMapping("/") public class UploadFileTest { /** * 上傳文件測(cè)試 * @param files * @param map * @return */ @RequestMapping(value = "/upload",method = RequestMethod.POST) public String upload(@RequestParam("files") MultipartFile[] files, ModelMap map){ List<String> results = MyfileUtils.uploadFile(files,"ds/sd","測(cè)試上傳的文件"); if(results!=null && results.size()>0){ map.addAttribute("urls", results.get(0)); } return "success"; } /** * 下載文件測(cè)試 * @param url * @return * @throws IOException */ @RequestMapping(value = "/download") public ResponseEntity<byte[]> getFile(@RequestParam("url")String url) throws IOException { return MyfileUtils.downloadFile(url,"下載的文件"+ url.substring(url.lastIndexOf("."))); } }
下載成功的頁面的jsp為:
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <html> <head> <title>Title</title> </head> <body> <h1>success!</h1> <br> <a href="/download?url=${urls}" rel="external nofollow" >下載上傳的文件</a> </body> </html>
里面提供了下載的按鈕(根據(jù)我們SpringMVC的視圖解析器的配置我們的所有頁面都在WEB-INF/views/文件夾下)。
特別注意的是頁面上要啟用el表達(dá)式否則el表達(dá)式在頁面上會(huì)失效!到現(xiàn)在為止,我們的代碼工作已經(jīng)編寫完成了,接著進(jìn)行測(cè)試:
這樣我們文件上傳和下載的任務(wù)就算完成了。
備注:
1.用戶可以再user-setting.properties中指定文件存放的更目錄
2.用戶在上傳文件還可以指定次級(jí)目錄,比如根目錄+(次級(jí)目錄)+(新指定的文件名).文件后綴
3.文件都是保存在服務(wù)器內(nèi)部的,能夠保存小量的文件對(duì)于大型的文件需要考慮其他專門的文件存儲(chǔ)的解決方案,本工具類能夠?qū)崿F(xiàn)中小型項(xiàng)目文件上傳和下載的任務(wù)。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
java抓取12306信息實(shí)現(xiàn)火車余票查詢示例
這篇文章主要介紹了java抓取12306信息實(shí)現(xiàn)火車余票查詢示例,需要的朋友可以參考下2014-04-04spring的applicationContext.xml文件與NamespaceHandler解析
這篇文章主要介紹了spring的applicationContext.xml文件與NamespaceHandler解析,Spring容器啟動(dòng),在創(chuàng)建BeanFactory時(shí),需要加載和解析當(dāng)前ApplicationContext對(duì)應(yīng)的配置文件applicationContext.xml,從而獲取bean相關(guān)的配置信息,需要的朋友可以參考下2023-12-12SpringBoot動(dòng)態(tài)修改日志級(jí)別的操作
這篇文章主要介紹了SpringBoot動(dòng)態(tài)修改日志級(jí)別的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-07-07SpringBoot配置連接兩個(gè)或多個(gè)數(shù)據(jù)庫的實(shí)現(xiàn)
本文主要介紹了SpringBoot配置連接兩個(gè)或多個(gè)數(shù)據(jù)庫的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-05-05使用jmx?exporter采集kafka指標(biāo)示例詳解
這篇文章主要為大家介紹了使用jmx?exporter采集kafka指標(biāo)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11postman?如何實(shí)現(xiàn)傳遞?ArrayList?給后臺(tái)
這篇文章主要介紹了postman?如何實(shí)現(xiàn)傳遞?ArrayList給后臺(tái),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-12-12