5.Spring Boot 自定义配置、导入XML配置与外部化配置

在Spring Boot中导入和解析XML文件的实践 总结来说,在Spring Boot项目中导入和解析XML文件主要分为两步:一是通过Spring的Resource机制获取XML文件资源,二是利用诸如DOM4J这样的XML解析库将XML文件转换为可操作的对象结构。}上述代码中,我们首先通过​​ClassPathResource​​加载类路径下的"example.xml"文件,然后使用​​SAXReader​​将其读取并解析成一个​​Document​​对象,这样就可以对XML文档进行各种操作了。}以上代码展示了如何获取XML文件的所有子节点及其名称和值。 阅读详情

Spring Boot 自定义配置、导入XML配置与外部化配置

      在这里我会全面介绍在Spring Boot里面如何自定义配置,更改Spring Boot默认的配置,以及介绍各配置的优先级顺序。Spring Boot使用一个全局的配置文件application.properties,Spring Boot 支持使用YAML语言的配置文件,YAML是以数据位中心的语言,所以使用application.yml作为全局配置也是同样的效果,如果使用YAML替代properties注意写法,冒号后面要加个空格,否则会解析不出来。而且在Spring Boot里面配置名称支持多种方式,例如:server.ssl.key-store,可以写成:server.ssl.keyStore都是可以的。下面具体详细介绍。

1.引用XML文件配置

      在实际项目中有的情况需要使用到XML配置文件,或者是你还不习惯用Java 配置的方式,那么你可以通过在入口启动类上加上@ImportResource(value = { "路径" })或者使用@ImportResource(locations= { "路径" }),一样的效果,多个XML文件的话你可以用逗号“,”分隔,就这样轻而易举的引用XML配置。

2.引入多个@Configuration 配置类

      在实际项目中可能不会把所有的配置都放在一个配置类(用@Configuration注解的类)中,可能会分开配置。这时可以用@Import注解引用。

3.引用自定义properties

      Spring Boot使用全局配置(application.properties)提供了很多的默认的配置属性。在开发的时候,大多数会用到自定义的一些配置属性,例如:指定上传文件保存的路径,定义:file.upload.stor-path=E:/test/,Spring Boot 提供了@Value注解获取properties中的属性,还提供了基于类型安全的配置方式,通过@ConfigurationProperties将properties属性注入到一个Bean中,在1.4以上版本官方不建议使用@ConfigurationProperties来指定properties文件位置。接下来请看实例:
      在pom.xml中加入以下依赖:
<dependency>  
          <groupId>org.springframework.boot</groupId>  
          <artifactId>spring-boot-configuration-processor</artifactId>  
          <optional>true</optional>  
</dependency> 
第一种:
     (1) 在src/main/resources下新建application.properties文件并加入以下代码:
file.upload.stor-path=E:/test/
      (2)直接使用@Value注解方式,具体代码如下:
package com.chengli.springboot.helloworld;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class SampleController {
	@Value(value = "${file.upload.stor-path}")
	private String storPath;

	@RequestMapping("/")
	String home() {
		return "Hello World! file.upload.stor-path为:" + storPath;
	}

	public static void main(String[] args) throws Exception {
		SpringApplication springApplication = new SpringApplication(SampleController.class);
		springApplication.run(args);
	}
}
第二种:
      属性配置放在application.properties文件中,使用@ConfigurationProperties将配置属性注入到Bean中,代码如下:
      (1)定义FileUploadProperties类
package com.chengli.springboot.helloworld;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "file.upload")
public class FileUploadProperties {
	private String storPath;

	public String getStorPath() {
		return storPath;
	}

	public void setStorPath(String storPath) {
		this.storPath = storPath;
	}
}
      (2)入口启动类代码如下:
package com.chengli.springboot.helloworld;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class SampleController {
	@Autowired
	private FileUploadProperties fileUploadProperties;

	@RequestMapping("/")
	String home() {
		return "Hello World! file.upload.stor-path为:" + fileUploadProperties.getStorPath();
	}

	public static void main(String[] args) throws Exception {
		SpringApplication springApplication = new SpringApplication(SampleController.class);
		springApplication.run(args);
	}
}
      注意:这里我对FileUploadProperties使用了@Component注解,如果没有使用@Component注解,则需要在入口启动类上加上@EnableConfigurationProperties注解。Spring Boot 在properties文件中支持使用SpEL表达式,可以进行校验(校验注解使用的是javax.validation)等操作。
例如以下:
(1)随机数:
          test.int.random=${random.int}
(2)数组注入
          test.int.random[0]=${random.int}
          test.int.random[1]=${random.int}
(3)校验
         @NotNull
         private String storPath;

4.外部化配置(配置方式与优先级)

      Spring Boot 允许外化配置,Spring Boot使用了一个特别的PropertySource次序来允许对值进行覆盖,覆盖的优先级顺序如下:
  (1)Devtools全局设置主目录(~ /.spring-boot-devtools.properties 为活跃的)。
  (2)@TestPropertySource注解在Test。
  (3)@SpringBootTest#properties 注解在Test。
  (4)命令行参数。
  (5)从SPRING_APPLICATION_JSON属性(内联JSON嵌入在一个环境变量或系统属性)。
  (6)ServletConfig init参数。
  (7)ServletContext init参数。
  (8)JNDI属性java:comp/env。
  (9)Java系统属性(System.getProperties())。
  (10)操作系统环境变量。
  (11)RandomValuePropertySource配置的random.*属性值
  (12)打包在jar以外的application-{profile}.properties或application-{profile}.yml配置文件
  (13)打包在jar以内的application-{profile}.properties或application-{profile}.yml配置文件
  (14)打包在jar以外的application.properties或application.yml配置文件
  (15)打包在jar以内的application.properties或application.yml配置文件
  (16)@configuration注解类上的@PropertySource。
  (17)默认的属性(使用SpringApplication.setDefaultProperties指定)。
a) 通过命令行来修改默认参数,例如:
     启动命令:java -jar *.jar --name="chengli"
     以上的意思是,将name值修改为:chengli
b) 通过命令行来设置加载properties 例如:
     java -jar *.jar --spring.profiles.active=dev
     这里如果不了解profile的话,后面的文章中会介绍到。


5.application.properties文件按优先级,优先级高的会覆盖优先级低的

   优先级顺序如下:
  (1)当前目录下的一个/config子目录
  (2)当前目录
  (3)一个classpath下的/config包
  (4)classpath根目录
tomcat中配置文件server.xml如何配置? tomcat中配置文件server.xml如何配置? server.xml实则代表tomcat的架构设计。tomcat最顶层的容器是Server,该容器代表整个服务器,每个tomcat只有一个Server,每个Server可以包含多个Service,用于提供具体的服务。 在Service中包含tomcat的2个核心组件:Connector(用于接收请求并将该请求封装成Request和Respons... 阅读详情

相关推荐

Spring Boot 入门与核心配置(新手)

**一、**Spring Boot 入门 1、Spring Boot 简介 简化Spring应用开发的一个框架; 整个Spring技术栈的一个大整合; J2EE开发的一站式解决方案; 2、微服务 2014,martin fowler 微服务:架构风格(服务微化) 一个应用应该是一组小型服务;可以通过HTTP的方式进行互通; 单体应用:ALL IN ONE 微服务:每一个功能元素最终都是一个可独...

weixin_45420231的博客 2411

Springboot 加载xml

1.springboot 加载xml 下面两种方式都可以 Spring Boot @ImportResource注释示例   Spring提供了一个 @ImportResource 注释,用于将spring-test.xml文件中的bean加载到Application Context中。 @ImportResource({ “ classpath *:spring-test.xml ” }) 在Spring Boot的入口类中我们使用: @SpringBootApplication @I

sinat_34338162的博客 6131

IntelliJ IDEA中Spring Boot项目启动与调试全流程详解

在Java企业级开发中,Spring Boot凭借其约定优于配置的理念和自动装配机制,极大地简化了应用的创建和部署流程。其核心原理在于通过内嵌Servlet容器和Starter依赖,实现了开箱即用的快速开发体验。这一技术价值在于显著提升了开发效率,降低了微服务架构的入门门槛,广泛应用于Web服务、API接口和企业级后台系统构建。对于开发者而言,掌握在主流IDE如IntelliJ IDEA中高效启动、配置和调试Spring Boot项目是关键的工程实践技能。本文聚焦于**项目导入**与**热部署**等核心环节

weixin_33912638的博客 374

Spring Boot 加载自定义配置文件

Spring Boot免除了项目中大部分的手动配置,对于一些特定情况,我们可以通过修改全局配置文件以适应具体生产环境,可以说,几乎所有的配置都可以写在application.peroperties或application.yaml文件中,Spring Boot会自动加载全局配置文件从而免除我们手动加载的烦恼。但是,如果我们自定义配置文件,Spring Boot是无法识别这些配置文件的,此时就需要我们手动加载。使用Spring Initializr创建Spring Boot项目——ConfigDemo01。

梁辰兴的博客 4655

Spring Boot 实现多环境配置动态解析

Spring Boot 实现多环境配置动态解析 1 什么是外部化配置? SpringBoot官方解释如下: Spring Boot lets you externalize your configuration so that you can work with the same application code in different environments. You can use properties files, YAML files, environment variables, and co

weixin_40055163的博客 420

在Spring Boot中加载XML配置的完整步骤

主要给大家介绍了关于在Spring Boot中加载XML配置的完整步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

【JAVA 进阶】Spring Boot 自动配置原理与自定义 Starter 实战

本文系统介绍了Spring Boot自动配置的核心原理与实现。主要内容包括:1)自动配置的设计哲学与关键组件(@SpringBootApplication、AutoConfiguration类、条件注解);2)自动配置加载流程,包括Spring Boot 3的AutoConfiguration.imports机制;3)条件化注入的常见注解(@ConditionalOnClass等)与组合使用;4)外部化配置绑定(@ConfigurationProperties)及其与自动配置的联动。文章旨在帮助开发者深入理

CodeSuc 的技术博客 2869

【深度学习】基于BERT模型的情感分析(附实战完整代码+数据集)

情感分类是一个快速发展的研究领域,尽管众多模型和数据集在二分类任务中显示出很高的准确性,但细粒度的情感分类任务仍然是一个很大改进空间的领域。分析SST-5数据集,Munikar等人的先前工作表明,嵌入工具BERT允许使用简单的模型来实现最新的准确性。

aaaa_hsjsueu的博客 2万+

Spring Boot启动原理与核心机制详解

Spring Boot作为Java生态中主流的应用开发框架,其自动配置机制和约定优于配置的设计理念大幅简化了Spring应用的初始化流程。框架通过@EnableAutoConfiguration注解实现智能化的bean装配,结合条件注解(@Conditional)体系实现按需加载,这种设计既保证了灵活性又降低了配置复杂度。在微服务架构和云原生场景下,Spring Boot的嵌入式容器支持和外部化配置系统(如application.properties)为应用部署提供了极大便利。深入理解SpringAppli

weixin_33744141的博客 361

E28 LoRa模块透传 定点传输 RSSI测试与MicroPython应用

测试说明 测试模块数:3 测试模式:配置模式和传输模式 如果没有检测到串口,首先检查是否安装串口驱动CH341SER,下载链接,提取码:vaw2 工作模式 模式(0-3) M2 M1 M0 模式介绍 备注 0 传输模式 1 0 0 串口打开,无线打开,连续透明传输 空速支持手动配置和自适应波特率自动调节;连续模式双方波特率必须一致 1 RSSI 1 0 1 串口打开,无线打开,RSSI功能打开 模块每100ms输出RSSI强度值 2 测距模式 1 1 0 保留 - 3 配置模式

GniLAY1022的博客 4240

Vivado 2023.1及更早版本永久License全功能解锁:HLS、System Generator等IP核使用详解

本文深入解析Vivado 2023.1及更早版本的全功能许可证,详细指导如何解锁HLS、System Generator等高级IP核。通过许可证类型对比、功能验证方法和实战应用指南,帮助FPGA开发者充分利用Vivado工具套件,提升复杂系统设计和算法加速的效率。

weixin_31286719的博客 375

Spring Boot配置安全实践:环境变量与外部化配置实现敏感信息零提交

在软件工程中,配置管理是连接代码与运行环境的关键环节,其核心在于实现配置与代码的分离。这一原理通过外部化配置机制,将应用运行所需的参数(如数据库连接、API密钥等)从代码中抽离,交由环境动态注入。其技术价值在于提升安全性、增强环境适应性和促进团队协作。在应用场景上,无论是微服务架构、容器化部署还是多环境交付,安全灵活的配置管理都是基石。本文聚焦于Spring Boot框架,深入探讨如何利用环境变量、外部配置文件及优先级加载策略,构建一套“无码”(即无敏感信息明文)的版本控制方案,确保数据库密码、JWT密钥等

weixin_30781433的博客 423

NoC架构深度解析:从拓扑结构到流量控制的全面指南

本文深入解析了片上网络(NoC)架构,从总线架构的瓶颈出发,阐述了NoC作为芯片内部“交通网”的核心优势。文章详细探讨了主流拓扑结构(如Mesh、Torus、Ring)的选型权衡,并系统介绍了数据包格式、路由算法、路由器流水线、流量控制机制以及网络接口(NI)设计,为理解现代多核SoC的通信基石提供了全面指南。

gg901的博客 1038

Hazelcast Jet Spring Boot Starter:自动配置原理、条件加载与实战接入指南

本文围绕 [docs/design/jet/004-spring-boot-starter.md](https://link.gitcode.com/i/1e02480b53ba017c48c60b2739d0f6a8) 设计文档,系统讲解 Hazelcast Jet 官方 Spring Boot Starter 的设计与实现:包括基于 `META-INF/spring.factories` 的自

gitblog_00750的博客 401

详解YOLOv8网络结构/环境搭建/数据集获取/训练/推理/验证/导出/部署

YOLO(You Only Look Once)系列算法因其高效、准确等特点而备受瞩目。由2023年Ultralytics公司发布了YOLO的最新版本YOLOv8是结合前几代YOLO的基础上的一个融合改进版。本文YOLOv8网络结构/环境搭建/数据集获取/训练/推理/验证/导出/部署,从网络结构的讲解从模型的网络结构讲解到模型的部署都有详细介绍,同时在本专栏中还包括YOLOv8模型系列的改进包括个人提出的创新点,传统卷积、注意力机制、损失函数的修改教程,能够帮助你的论文获得创新点。

Snu77的博客 8万+

模拟量输入功能块 S_ITR(Easy系列PLC完整ST源代码)

IN Input INT 输入数字量 1IN ISH INT 输入数字量上限 2IN ISL INT 输入数字量下限 3IN OSH REAL 输出工程量上限 4IN OSL REAL 输出工程量下限 5OUT OUTPUT REAL 输出工程量 6VAR temp1 REAL 临时变量1 7VAR temp2 REAL 临时变量2 8。

RXXW_Dor的博客 713

从Spring迁移到Spring Boot

在本文中,我们将研究如何将现有的Spring框架应用程序迁移到SpringBoot应用程序。Spring Boot并不是为了取代Spring,而是为了使使用它更快更容易。因此,迁移应用程序所需的大多数更改都与配置有关。在大多数情况下,我们的自定义控制器和其他组件将保持不变。使用Spring Boot进行开发有几个优点:首先,我们需要一组新的依赖项。 springboot提供了方便的starter依赖项 ,这些依赖项描述符可以为某些功能引入所有必要的技术。这样做的好处是,您不再需要为每个依赖项指定版本,而是让

JavaShark的博客 1519

基于ESP32的智能停车场管理系统开发

智能停车场管理系统通过引入物联网(IoT)技术,实现对停车场内车辆的实时监控、空闲车位的管理、车辆的入场与出场控制等功能,大大提高了停车场的利用率和管理效率。通过集成物联网技术、云平台以及先进的传感器和执行器,系统不仅能实时监控停车场的车位状态,还能提供更好的用户体验。本文将介绍如何基于ESP32开发一个智能停车场管理系统,涵盖系统架构、硬件选择、软件开发以及最新技术的应用,帮助开发者实现高效的智能停车管理。ESP32的代码主要负责处理车位传感器的数据,控制LED指示灯的状态,以及与云平台进行数据交互。

2201_76125393的博客 910

Spring Boot核心原理与实践:从自动配置到生产部署

在Java企业级应用开发中,约定大于配置是一种重要的设计范式,旨在通过预设最佳实践来减少繁琐的XML和代码配置,从而提升开发效率。其核心原理在于依赖自动装配和条件化加载机制,通过分析类路径、Bean定义和属性设置,智能地初始化应用组件。这一技术价值在于显著降低了项目启动和维护的复杂性,使得开发者能更专注于业务逻辑实现。在微服务架构和云原生场景下,这种开箱即用的特性尤为重要,它简化了服务的独立部署与扩展。Spring Boot作为该范式的杰出代表,通过自动配置、Starter依赖和内嵌容器等机制,将这一理念发

weixin_33831673的博客 388

【DRAM存储器十五】DDR介绍-关键技术之DLL和prefetch

详述DDR DLL和预取原理以及几个DDR相对初代SDRAM新增的时序参数

highman110的博客 4357

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Apache Dubbo Spring Boot 项目实战指南:从零搭建 Dubbo Provider 与 Consumer

本指南以 Apache Dubbo Spring Boot Project 官方 README(仓库根目录 [README.md](https://link.gitcode.com/i/8a7e739646bad9b905def8a5dbde4b86))为骨架,完整讲解该开源项目的历史背景、Maven 引入方式、基于 Spring Boot 自动配置的 Dubbo 服务提供方(Provider)与

gitblog_00895的博客 199

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

深入解析Spring Boot自动配置:从原理到自定义Starter实战

在Java企业级开发中,依赖注入与配置管理是框架设计的核心概念。Spring Boot通过自动配置机制,实现了‘约定大于配置’的理念,其原理基于条件化Bean注册与外部化配置绑定。这项技术的核心价值在于大幅简化了项目初始化与第三方组件集成的复杂度,提升了开发效率。在实际应用场景中,开发者通过引入Starter依赖即可快速集成数据库、缓存等中间件,无需编写冗长的XML或Java Config。本文聚焦于自动配置的底层实现,深入剖析了@EnableAutoConfiguration、spring.factori

weixin_33816821的博客 312

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

Spring Boot核心原理与生产实践指南

Spring Boot作为Java生态中主流的脚手架框架,其核心价值在于通过约定优于配置原则简化企业级应用开发。自动装配机制基于条件注解实现智能bean注册,起步依赖则封装了常见技术栈的标准化集成方案。在微服务架构下,Spring Boot的嵌入式容器设计和Actuator监控端点大幅降低了运维复杂度,配合外部化配置机制可实现灵活的环境适配。开发者通过自动配置报告和依赖分析工具能有效排查组件冲突问题,而合理的项目结构规划是保证组件扫描正常工作的前提。在云原生场景中,Spring Boot与Docker、Ku

weixin_33709219的博客 389

《SpringBoot 3:入门与应用实战》第 5 章 使用 Spring Boot 阅读笔记 9

《SpringBoot 3:入门与应用实战》第 5 章 使用 Spring Boot 阅读笔记 9

道友 352

Spring Boot自动配置核心原理与手写starter实战解析

Spring Boot之所以能大幅简化企业级应用开发,核心在于其自动配置机制——框架通过约定优于配置和条件装配,在启动时动态创建所需Bean。理解这一原理,是掌握Spring Boot从“会用”走向“懂用”的关键。自动配置依赖@ConditionalOnClass、@ConditionalOnMissingBean等条件注解实现按需加载,并结合@ConfigurationProperties完成外部化配置绑定,让开发者只需引入依赖即可获得默认能力。这一机制广泛适用于Web应用、中间件集成及公共组件封装等场景

weixin_34318272的博客 401

1.spring boot基础

Spring Boot 是目前流行的微服务框架 倡导 约定优先于配置” 其设 目的是用来简化新 Spring 应用的初始化搭建以及开发过程。Spring Boot 提供了很多核心的功 能,比如自动化配置starter(启动器) 简化 Maven配置、内嵌 Servlet 容器、应用监控等功能, 让我们可以快速构建企业级应用程序。特性:创建独立的 Spring 应用程序。嵌入式 Tomcat、 Jetty、 Undertow 容器(jar)

m0_49054880的博客 1296
上一篇: 4.Spring Boot Starter POMs 介绍
下一篇: 6.Spring Boot 自定义Banner
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值