Spring杂记之--Spring配置文件

避坑指南:STM32CubeMX安装后,你的第一个工程为什么中文全是乱码? 本文详细解析了STM32CubeMX安装后中文乱码问题的根源及解决方案。从诊断乱码现象到分析编码冲突背景,提供了新项目UTF-8化、旧项目GBK兼容及版本降级等多种实用方案,帮助开发者彻底解决这一常见问题。 阅读详情

学习spring时候随手记录的一些笔记。

1. Spring配置文件格式如下

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">
    <import resource="xx.xml"/>
    <bean id="bean1" class="...">
        <!-- collaborators and configuration for this bean go here -->
    </bean>

    <bean name="bean2" class="...">
        <!-- collaborators and configuration for this bean go here -->
    </bean>

    <!-- more bean definitions go here -->
    <alias alias="bean3" name="bean2"/>  别名
</beans>

Spring容器启动的基本条件:

  • Spring的框架类包
  • Bean配置信息
  • Bean的实现类


Bean的元数据信息:

  • Bean的实现类
  • Bean的属性信息
  • Bean的依赖关系
  • Bean的行为配置
  • Bean的创建方式

2 Spring Bean的命名:

用一个简单的例子说明:

首先,定义HelloWorld接口:

package com.company.springdemo2;

public interface HelloWorld {
	public void sayHello();
}

定义HelloWorldImpl实现接口类:

package com.company.springdemo2;

public class HelloWorldImpl implements HelloWorld {

	@Override
	public void sayHello() {
		System.out.println("hello world");
	}

}

配置文件书写:
  • 全限定类名,唯一: <bean class="com.company.springdemo2.HelloWorldImpl"/>
  • 指定id,唯一:<bean id="helloWorld" class="com.company.springdemo2.HelloWorldImpl"/>
  • 指定name,唯一:<bean name="hello" class="com.company.springdemo2.HelloWorldImpl"/>
  • 同时指定id和name:<bean id="helloid" name="helloname" class="com.company.springdemo2.HelloWorldImpl"/> 在主函数中,id和name都能获取实例,这里不再说明。
  • 指定多个name,第一个为标识符,其他为别名,唯一:用分隔符分开。

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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">
	
	<bean class="com.company.springdemo2.HelloWorldImpl"/>
	<bean id="helloWorld" class="com.company.springdemo2.HelloWorldImpl"/>
	<bean name="hello" class="com.company.springdemo2.HelloWorldImpl"/>
</beans>


Main方法:

package com.company.springdemo2;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {

	public static void main(String[] args) {
		BeanFactory beanFactory = new ClassPathXmlApplicationContext("conf/helloworld.xml");
//		//class
//		HelloWorld helloWorld = beanFactory.getBean(HelloWorldImpl.class);
//		helloWorld.sayHello();
//		//id
//		HelloWorld helloWorldID = beanFactory.getBean("helloWorld", HelloWorld.class);
//		helloWorldID.sayHello();
		//name
		HelloWorld helloWorldName = beanFactory.getBean("hello",HelloWorld.class);
		helloWorldName.sayHello();
	}
}


3. Spring实例化Bean

SpringIOC根据Bean定义的配置元素数据使用反射机制创建Bean.

  • 使用构造器实例化bean
  • 使用静态工厂方法
  • 使用实例工厂方法


3.1 构造器实例化: 构造器实例化是最简单的方式,Spring IOC容器既能使用默认空构造器也能使用有参数构造器两种方式创建Bean

用一个实例来说明;

首先,与上面相同,创建接口和实现类,这里,实现类有两个构造方法,有参数的和无参数的:

package com.company.springdemo3;

public interface HelloWorld {
	public void sayHello();
}

package com.company.springdemo3;

public class HelloWorldImpl implements HelloWorld {
	private String message;
	/**
	 * 空构造器
	 * */
	public HelloWorldImpl() {
		this.message = "hello world";
	}
	/**
	 * 带参数的构造器
	 * */
	public HelloWorldImpl(String message){
		this.message = message;
	}

	@Override
	public void sayHello() {
		System.out.println(message);
	}

}

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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">
	<!-- 无参数构造方法 -->
	<bean id="helloworldNoArgs" class="com.company.springdemo3.HelloWorldImpl"/>
	<!-- 有参数构造 -->
	<bean id="helloworldWithArgs" class="com.company.springdemo3.HelloWorldImpl">
		<!-- 指定参数 -->
		<constructor-arg index="0" value="hello args"/>
	</bean>
		
</beans>

Main

package com.company.springdemo3;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {

	public static void main(String[] args) {
		BeanFactory beanFactory = 
				new ClassPathXmlApplicationContext("conf/hello2.xml");
//		HelloWorld hello = beanFactory.getBean("helloworldNoArgs", HelloWorld.class);
//		hello.sayHello();
		HelloWorld hello = beanFactory.getBean("helloworldWithArgs", HelloWorld.class);
		hello.sayHello();
	}

}


3.2. 静态工厂实例化:使用静态工厂的方式除了指定必须的class属性,还要指定factory-method属性来指定实例化Bean的方法,而且使用静态工厂方法也允许指定方法参数,Spring Ioc容器将调用此属性来获取Bean

在3.1穿件的类的基础上,创建一个工厂类:

package com.company.springdemo3;

public class HelloWorldStaticFactory {
	public static HelloWorld newInstance(String message){
		return new HelloWorldImpl(message);
	}

}

配置文件: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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">
	<!-- 静态工厂方法方法 -->
	<bean id="helloworldStaticFactory" 
		class="com.company.springdemo3.HelloWorldStaticFactory"
		factory-method="newInstance">
		<constructor-arg index="0" value="hello static factory"/>
	</bean>
		
</beans>

在Main函数中测试:

		BeanFactory beanFactory = 
				new ClassPathXmlApplicationContext("conf/hello3.xml");
		HelloWorld hello = beanFactory.getBean("helloworldStaticFactory", HelloWorld.class);
		hello.sayHello();

3.3 实例工厂实例化:使用实例工厂方式不能指定class属性,此时必须使用factory-bean属性指定工厂bean,factory-method属性指定实例化bean的方法,而且使用实例工厂方法允许指定方法参数,方式和使用构造器方式一样:

添加实例工厂类:

package com.company.springdemo3;

public class HelloWorldInstanceFactory {
	public HelloWorld newInstance(String message){
		return new HelloWorldImpl(message);
	}
}

添加配置文件.xml:

	<!-- 1.定义实例工厂bean -->
	<bean id="helloworldInstanceFactory" 
		class="com.company.springdemo3.HelloWorldInstanceFactory"/>
	<!-- 2使用实例工厂Bean创建Bean -->
	<bean id="helloworldInstance" factory-bean="helloworldInstanceFactory" 
		factory-method="newInstance">
		<constructor-arg index="0" value="hello instance factory"></constructor-arg>	
	</bean>

在Main函数中测试:

		BeanFactory beanFactory = 
				new ClassPathXmlApplicationContext("conf/hello3.xml");
		HelloWorld hello = beanFactory.getBean("helloworldInstance", HelloWorld.class);
		hello.sayHello();


4. Spring Bean的作用域:

Spring Bean中的作用域,在配置文件中即是“scope”, 在面向对象程序设计中一般指对象或变量的可见范围,而在spring容器中是指其创建的Bean对象相对于其他Bean对象的请求可见范围。

Bean的作用域类型与配置:在Spring容器中,一共提供了5中作用域类型,在配置文件中,通过scope来设置bean的作用域范围。

作用域描述
singleton该作用域将 bean 的定义的限制在每一个 Spring IoC 容器中的一个单一实例(默认)。<bean id="..." class="..." scope="singleton"/>
prototype该作用域将单一 bean 的定义限制在任意数量的对象实例。<bean id="..." class="..." scope="singleton"/>
request该作用域将 bean 的定义限制为 HTTP 请求。只在 web-aware Spring ApplicationContext 的上下文中有效。
session该作用域将 bean 的定义限制为 HTTP 会话。 只在web-aware Spring ApplicationContext的上下文中有效。
global-session该作用域将 bean 的定义限制为全局 HTTP 会话。只在 web-aware Spring ApplicationContext 的上下文中有效。
表格来自:极客学院wiki http://wiki.jikexueyuan.com/project/spring/bean-scopes.html



学习spring随手记下的一些笔记,具体可以参考:www.jikexueyuan.com








【人工智能】 WebDev Arena:实时AI Web开发竞赛的技术探索与价值 《AI编程竞赛推动Web开发技术创新》摘要:WebDev Arena作为聚焦Web开发领域的实时AI编程竞赛,通过标准化竞技环境检验AI模型在代码生成、问题解决等方面的能力。竞赛覆盖前端、后端等全流程开发环节,采用实时评分机制,推动AI对复杂Web需求的理解和多元技术栈适配。该赛事不仅促进AI编程技术创新,更为Web开发行业与AI技术融合搭建桥梁,有望提升开发效率、降低技术门槛。未来将拓展Web3.0等前沿技术主题,持续推动行业智能化发展。(150字) 阅读详情

相关推荐

3D缺陷检测实战:从点云处理到工业质检优化

本文深入探讨了3D缺陷检测在工业质检中的实战应用,详细阐述了从点云处理到深度学习模型部署的完整技术链路。文章通过PCB焊点检测等实际案例,分析了3D视觉相比2D检测在识别深度、形状等缺陷方面的优势,并分享了点云滤波、分割、特征提取以及利用YOLOv5等模型进行高效检测的优化心得与落地挑战。

weixin_28358083的博客 336

spring boot 配置文件杂记

bootstrap.yml与application.yml的加载都是在ConfigFileApplicationListener.postProcessEnvironment中完成的,在BootstrapApplicationListener中配置了spring.config.name与spring.config.location,在ConfigFileApplicationListener会根据这两个参数查找指定的文件进行加载(如果不存在则使用默认的). 如果bootstrap.yml中配置的属性会放在名

qi531621028的博客 232

5G 网络的移动性管理上下文对比介绍

5G 网络的移动性管理上下文对比介绍 4G/5G MM移动性管理机制对比 5G引入了新移动性管理状态,通过mobility pattern(移动方式)实现按需的移动性管理等。 MM的相关状态分为一下几种: RM状态(用户注册管理 注册态/非注册态)和CM状态(用户连接态/空闲态)独立;RM状态标识UE是否注册到网络,CM状态标识UE和核心网的信令连接是否存在。 RAN侧引入RRC-inactive state:UE(用户端)对于CN(核心网)而言处于连接态,对RAN(接入网)而言处于Ld..

m0_59032675的博客 4817

Spring杂记

文章目录1.如何获取Spring的实例?1.Spring配置文件内容的详细解释1.scope2.init-method和destory-method3.无参构造方式将bean注入容器4.依赖注入5.import1.Spring注解详解1.Spring如何集成Junit?1.Spring AOP1.Spring如何引入数据库连接池1.Spring如何引入jdbc1.Spring如何引入事务控制?1.当前没有事务时2.基于XML的声明式事务控制3.基于注解的声明式事务控制(重点) 什么叫杂记?就是很杂很乱,没

weixin_45014721的博客 1586

深度学习入门:使用CMSIS-NN在微控制器上部署模型的完整指南与Python Jupyter实践

CMSIS-NN是ARM为Cortex-M系列微控制器设计的神经网络库。它旨在提供一套高效、轻量级的神经网络API,使得开发者可以在资源受限的微控制器上运行深度学习模型。CMSIS-NN优化了各种常见的神经网络层,如卷积层、全连接层等,确保它们在微控制器上的运行效率。# 定义模型])# 编译模型# 训练模型这样,我们就得到了一个简单的手写数字识别模型。注意:为了简洁和清晰,本文中的代码可能不是最优的或最完整的实现。为了获得完整的项目和更多的优化技巧,请下载完整项目。

m0_57781768的博客 5882

UWB定位进阶:如何利用DW1000的CIR数据做NLOS信号识别?

本文深入探讨了如何利用DW1000芯片的信道脉冲响应(CIR)数据进行非视距(NLOS)信号识别,以提升UWB定位精度。通过分析CIR数据的核心价值、预处理方法、特征提取技术以及机器学习模型构建,为研究人员和工程师提供了实用的解决方案,帮助克服室内定位中的NLOS挑战。

weixin_28729205的博客 474

Spring boot 传统的web 杂记

有模板引擎依赖会自动配置对应的视图解析器。无模板引擎依赖:不会自动配置视图解析器,项目通常作为 API 服务。(主流)手动配置:通过类和@Bean方法自定义视图解析器。应该优先使用 Thymeleaf 或 FreeMarker,它们与 Spring Boot 集成更简单,无需额外配置。全新项目 还是restful吧。传统项目用的比较多一点,主流还是建议各位用前端框架。Thymeleaf是一款Java 开源的模板引擎,用于在服务端动态渲染 HTML/XML 页面。它的设计目标是让模板在浏览器中直接预览。

wh_xia_jun的专栏 1192

有源滤波电路设计

目录一、低通滤波器1、同相输入低通滤波器(1)一阶低通滤波电路(2)二阶低通滤波电路(压控电压源;Sallen-Key)2、反相输入低通滤波器(1)一阶低通滤波电路(2)二阶低通滤波电路(无限增益多路反馈)二、高通滤波器1、同相输入高通滤波器(1)一阶高通滤波电路(2)二阶高通滤波电路(压控电压源;Sallen-Key)2、反相输入高通滤波电路(1)二阶高通滤波电路(无限增益多路反馈) 一、低通滤波器 1、同相输入低通滤波器 (1)一阶低通滤波电路 即在一阶无源低通滤波器的基础上,加了一个集成运放。 它的

qq_41873236的博客 3万+

【JavaEE之Spring】SpringBoot杂记

这是一篇关于SpringBoot的杂记,为什么说是杂记?因为这是我零零散散把自己觉得有用的东西记录了下来,主要是给自己写的,或许有人看起来会觉得很乱,你可以评论问我哦,好了,接下来进入正题 Spring Boot: SpringBoot的步骤: 0.创建Maven项目 1.加依赖–添加SpringBoot的父母约定依赖,不需要Spring的物料清单 添加自己所需要的SpringBoot约定的的...

eternal_01的博客 716

基于YOLOv11的建筑图纸物体检测系统设计与实现

包含多种建筑平面图,标注了墙体、门窗等元素:CAD格式的建筑图纸数据集:专门针对建筑元素的标注数据集自定义数据集:使用LabelImg等工具自行标注的建筑图纸本文以FloorPlanDataset为基础,结合部分自定义标注数据构建混合数据集。wall (墙体)door (门)window (窗)stair (楼梯)furniture (家具)text (文字标注)dimension (尺寸标注)column (柱子)

YOLO 536

自然语言处理(扩展学习1):Scheduled Sampling(计划采样)与Teacher forcing(教师强制)

作者:安静到无声作者简介:人工智能和硬件设计博士生、优快云与阿里云开发者博客专家,多项比赛获奖者,发表SCI论文多篇。o( ̄▽ ̄)d。

安静到无声 2143

spring杂记

org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory#getWebServer 方法中调用的,再看getWebServer()方法哪里调用的。org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory#customizeConnector()方法中调用的。重要类 ServerProperties。

Lonely_Devil的博客 853

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

关于Spring杂记

一、Spring 是什么? 是一个开源框架,为简化企业应用而生的,Spring 是一个IOC 和AOP容器框架。 二、相关概念 1、轻量级:Spring 是非侵入式的,基于Spring开发的应用中的对象,可以不依赖于Spring的API。 2、依赖注入和控制反转(DI和IOC) IO...

chuangju3476的博客 191

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

深度学习工具包 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 杂记

1、获取官网的jar包,源码和文档 直接在地址栏输入:http://repo.springsource.org/libs-release-local/   2、Spring 和 SpringMvc 配置文件加载顺序 由于在 web.xml 中 listener加载顺序优先于servlet ,故加载顺序Spring&gt;SpringMvc,如果你的SpringMvc配置文件在WEB-I...

new03的专栏 143

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

[Java]struts,spring,svn杂记

------struts2整合spring----------------------------------------------------- struts2过滤器负责在Tomcat启动时运行,加载和创建静态注入项(也可以在配置文件中加载我们写的类的 ),管理struts2容器。负责加载Action,接收特点结尾的请求,为每个请求创建对应Action对象,执行其 相应方法...

ghbfgb的博客 1551

spring 杂记

spring3使用记录,方便以后回忆整理 1.spring3 注解 参考:http://www.ibm.com/developerworks/cn/opensource/os-cn-spring-iocannt/ Spring 本身提供了一个丰富的并且是与具体的数据访问技术无关的数据访问异常结构,用于封装不同的持久层框架抛出的异常,使得异常独立于底层的框架。 <co...

Xiaomi8261的博客 217

Spring JUnit杂记

第一步:导入spring-test-..*.RELEASE.jar 第二步:使用junit提供的一个注解,把原有的main函数替换掉,换成spring提供的。@RunWith 要换的SpringJunit4ClassRunner 第三步:使用spring提供注解告知spring,配置文件或注解类所在的位置@ContextConfiguration 自动注入ICustomerService cs...

wujingchangye的博客 139

Spring杂记(自上而下顺着链条看)

本篇文章都是本人的理解,看不懂可以评论,会回复评论。持续更新… 讲到Spring就一定绕不开IOC、AOP两个概念了,在我看来Spring得一切都基于IOC,所以先聊IOC吧。 IOC 一、首先看看IOC的作用,我们可以试着写一个从service层到dao层的用例,会发现如果是一层一层实现了这个用例,将来要修改就要一层层改,这样耦合度极高,而把控制权交给第三方(Test中new一个serviceImpl来set一个userDao),会解耦。此时,主动去new一个dao对象叫正向获取,而等着serviceI

su_rxy的博客 910

spring调用mybatis的dao时是怎样的_Spring 杂记

Bean 的生命周期Spring Bean 的生命周期,大致上可以分为创建、使用、销毁三个阶段。具体由可以分为以下几个阶段:实例化 Bean对于 BeanFactory 容器,当客户向容器请求一个尚未初始化的 bean 时,或初始化 bean 的时候需要注入另一个尚未初始化的依赖时,容器就会调用 createBean 进行实例化。对于 ApplicationContext 容器,当容器启动结束后,...

weixin_39737001的博客 243

【spring】杂记

1.[spring aop]AOP核心概念 1、横切关注点对哪些方法进行拦截,拦截后怎么处理,这些关注点称之为横切关注点2、切面(aspect)类是对物体特征的抽象,切面就是对横切关注点的抽象3、连接点(joinpoint)被拦截到的点,因为Spring只支持方法类型的连接点,所以在Spring中连接点指的就是被拦截到的方法,实际上连接点还可以是字段或者构造器4、切入点(pointcut)对连接点进

qq523786283的博客 482

spring项目杂记5

1. 你添加jar到工程的时候是选择的 Add JARs 还是Add External JARs 如果是后者而添加的JAR不在workspace中的工程目录中,myeclipse是不会自动将该JAR复制到workspace下的工程目录中的 我把包放到WEB-INF下面,clean一下,工程就会自动引用了

NF160的专栏 859

Spring Boot 杂记

Spring Boot 推荐的基础POM文件 名称 说明 spring-boot-starter 核心 POM,包含自动配置支持、日志库和对 YAML 配置文件的支持。 spring-boot-starter-amqp 通过 spring-rabbit 支持 AMQP。 spring-boot-starter-aop 包含 spring-aop 和 AspectJ 来支持面...

ohyes 160

Spring——依赖注入杂记

一、 对象构造方法IOC创建的方式 1、默认使用无参构造方法  不用使用<constructor -arg /> 2、按照下标进行构造 3、通过类型匹配来构造 4、通过变量名直接使用 二、 xml配置详解 1、 alias别名: 2、 bean配置: 3、 import配置: 导入其他的配置文件xml。如果内容重名且类型重复,会被自动合并。一般用于团队开发使用,多人开发合并成一个配置文件进行操作。 三、 依赖注入 依赖:bean对象的创建依赖于容器 注入:bean对象中所有属性,由容

Andy24.的博客 324

Spring学习杂记

Spring容器 在Spring IOC容器读取Bean配置创建Bean实例之前,必须对它进行实例化。只有在容器实例化后,才可以从IOC容器里获取Bean实例并使用。 Spring提供了两种类型的IOC容器实现: -BeanFactory:IOC容器的基本实现 -ApplicationContext:提供了更多的高级特性,是BeanFactory的子接口。 -BeanFactory是Sp

Fasure_Smile的博客 426

杂记

parse 从语法上描述 wrapped 包装类 高淇58集讲述了String类的StringBuilder以及一些常用方法的使用 null指没有,而不是0;让一个对象=null后它在栈里分配了空间,但是在堆里没有类的构造;使用该对象调用方法通常会抛出NullPointerException异常 65讲到时间Date 66集DateFormat、SimpleDate...

测试 586
上一篇: Spring杂记
下一篇: caffe学习笔记13(补充)--关于ContrastiveLossLayer层
thystar
博客等级 码龄17年 407粉丝 151原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值