被面试官虐懵了,竟然是因为我不懂Spring中的@Configuration

面试官:@Configuration 和 @Component 的区别 昨天,一位朋友跟我反馈,在面试中被问到注解和@Component的区别。一句话概括就是中所有带@Bean注解的方法都会被动态代理,因此调用该方法返回的都是同一个实例。理解:调用类中的@Bean注解的方法,返回的是同一个示例;而调用@Component类中的@Bean注解的方法,返回的是一个新的实例。注意:上面说的调用,而不是从spring容器中获取!见最下面的示例 1 及 示例 2下面看看实现的细节。 阅读详情

在一次关于Spring注解的面试中,可能会经历面试官的一段夺命连环问:

(1)@Configuration有什么用?

(2)@Configuration和XML有什么区别?哪种好?

(3)Spring是如何基于来获取Bean的定义的?如何对Bean进行延迟初始化?

(4)@Autowired 、 @Inject、@Resource 之间有什么区别?

(5)@Value、@PropertySource 和 @Configuration?

(6)Spring如何处理带@Configuration @Import的类?

(7)@Profile有什么用?

(8)@Configuration 如何嵌套?

(9)Spring项目怎么进行单元测试?

(10)@Configuration 使用上有哪些约束?

@Configuration 基本说明

​ **定义:指示一个类声明一个或者多个@Bean 声明的方法并且由Spring容器统一管理,以便在运行时为这些bean生成bean的定义和服务请求的类。**例如:

@ConfigurationpublicclassAppConfig{@BeanpublicMyBeanmyBean(){returnnewMyBean();  }}

上述AppConfig 加入@Configuration 注解,表明这就是一个配置类。有一个myBean()的方法,返回一个MyBean()的实例,并用@Bean 进行注释,表明这个方法是需要被Spring进行管理的bean。@Bean 如果不指定名称的话,默认使用myBean名称,也就是小写的名称。

1. 通过注解启动

通过启动一个AnnotationConfigApplicationContext 来引导这个@Configuration 注解的类,比如:

AnnotationConfigApplicationContext ctx =newAnnotationConfigApplicationContext();ctx.register(AppConfig.class);ctx.refresh();

在web项目中,也可以使用AnnotationContextWebApplicationContext或者其他变体来启动。

新建一个SpringBoot项目(别问我为什么,因为这样创建项目比较快)。

(1)pom.xml 文件如下

<?xml version="1.0"encoding="UTF-8"?>4.0.0org.springframework.bootspring-boot-starter-parent2.1.5.RELEASE<!-- lookup parent from repository -->com.spring.configurationspring-configuration0.0.1-SNAPSHOTspring-configurationDemo project for Spring Boot1.8org.springframework.bootspring-boot-starter-testtestorg.springframeworkspring-context5.0.6.RELEASEorg.springframework.bootspring-boot-maven-plugin

在config 包下新建一个MyConfiguration环境配置,和上面的示例代码相似,完整的代码如下:

@ConfigurationpublicclassMyConfiguration{@BeanpublicMyBeanmyBean(){        System.out.println("myBean Initialized");returnnewMyBean();    }}

说明MyConfiguration 是一个配置类,能够在此类下面声明管理多个Bean,我们声明了一个MyBean的bean,希望它被容器加载和管理。

在pojo包下新建一个MyBean的类,具体代码如下

publicclassMyBean{publicMyBean(){        System.out.println("generate MyBean Instance");    }publicvoidinit(){        System.out.println("MyBean Resources Initialized");    }}

新建一个SpringConfigurationApplication类,用来测试MyConfiguration类,具体代码如下:

publicclassSpringConfigurationApplication{publicstaticvoidmain(String[] args){//        AnnotationConfigApplicationContext context = = new AnnotationConfigApplicationContext(MyConfiguration.class)// 因为我们加载的@Configuration 是基于注解形式的,所以需要创建AnnotationConfigApplicationContextAnnotationConfigApplicationContext context =newAnnotationConfigApplicationContext();// 注册MyConfiguration 类并刷新bean 容器。context.register(MyConfiguration.class);        context.refresh();    }}

(2)输出

myBean Initialized

generate MyBean Instance

从输出的结果可以看到,默认名称为myBean 的bean随着容器的加载而加载,因为myBean方法返回一个myBean的构造方法,所以myBean被初始化了。

2. 通过XML 的方式来启动

可以通过使用XML方式定义的<context:annotation-config />开启基于注解的启动,然后再定义一个MyConfiguration的bean,在/resources 目录下新建 application-context.xml 代码如下:

<?xml version="1.0"encoding="UTF-8"?>

      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd

      http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd

      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd"><!-- 相当于基于注解的启动类 AnnotationConfigApplicationContext-->

需要引入applicationContext.xml ,在SpringConfigurationApplication 需要进行引入,修改后的SpringConfigurationApplication如下:

publicclassSpringConfigurationApplication{publicstaticvoidmain(String[] args){        ApplicationContext context =newClassPathXmlApplicationContext("applicationContext.xml");    }}

输出:

myBean Initialized

generate MyBean Instance

基于ComponentScan() 来获取Bean的定义

@Configuration 使用@Component 进行原注解,因此@Configuration 类也可以被组件扫描到(特别是使用XMLcontext:component-scan元素)。

在这里认识几个注解:@Controller, @Service, @Repository, @Component

@Controller: 表明一个注解的类是一个"Controller",也就是控制器,可以把它理解为MVC 模式的Controller 这个角色。这个注解是一个特殊的@Component,允许实现类通过类路径的扫描扫描到。它通常与@RequestMapping 注解一起使用。

@Service: 表明这个带注解的类是一个"Service",也就是服务层,可以把它理解为MVC 模式中的Service层这个角色,这个注解也是一个特殊的@Component,允许实现类通过类路径的扫描扫描到

@Repository: 表明这个注解的类是一个"Repository",团队实现了JavaEE 模式中像是作为"Data Access Object" 可能作为DAO来使用,当与 PersistenceExceptionTranslationPostProcessor 结合使用时,这样注释的类有资格获得Spring转换的目的。这个注解也是@Component 的一个特殊实现,允许实现类能够被自动扫描到

@Component: 表明这个注释的类是一个组件,当使用基于注释的配置和类路径扫描时,这些类被视为自动检测的候选者。

也就是说,上面四个注解标记的类都能够通过@ComponentScan 扫描到,上面四个注解最大的区别就是使用的场景和语义不一样,比如你定义一个Service类想要被Spring进行管理,你应该把它定义为@Service 而不是@Controller因为我们从语义上讲,@Service更像是一个服务的类,而不是一个控制器的类,@Component通常被称作组件,它可以标注任何你没有严格予以说明的类,比如说是一个配置类,它不属于MVC模式的任何一层,这个时候你更习惯于把它定义为 @Component。@Controller,@Service,@Repository 的注解上都有@Component,所以这三个注解都可以用@Component进行替换。

来看一下代码进行理解:

定义五个类,类上分别用@Controller, @Service, @Repository, @Component, @Configuration 进行标注,分别如下

@ComponentpublicclassUserBean{}@ConfigurationpublicclassUserConfiguration{}@ControllerpublicclassUserController{}@RepositorypublicclassUserDao{}@ServicepublicclassUserService{}复制代码

在MyConfiguration上加上@ComponentScan 注解,扫描上面5个类所在的包位置。代码如下:

@Configuration@ComponentScan(basePackages ="com.spring.configuration.pojo")publicclassMyConfiguration{@BeanpublicMyBeanmyBean(){        System.out.println("myBean Initialized");returnnewMyBean();    }}复制代码

修改 SpringConfigurationApplication 中的代码,如下:

publicclassSpringConfigurationApplication{publicstaticvoidmain(String[] args){//        AnnotationConfigApplicationContext context = = new AnnotationConfigApplicationContext(MyConfiguration.class)//        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");AnnotationConfigApplicationContext context =newAnnotationConfigApplicationContext();        context.register(MyConfiguration.class);        context.refresh();// 获取启动过程中的bean 定义的名称for(String str : context.getBeanDefinitionNames()){            System.out.println("str = "+ str);        }        context.close();    }}复制代码

输出:

myBean Initialized

generate MyBean Instance

str = org.springframework.context.annotation.internalConfigurationAnnotationProcessor

str = org.springframework.context.annotation.internalAutowiredAnnotationProcessor

str = org.springframework.context.annotation.internalRequiredAnnotationProcessor

str = org.springframework.context.annotation.internalCommonAnnotationProcessor

str = org.springframework.context.event.internalEventListenerProcessor

str = org.springframework.context.event.internalEventListenerFactory

str = myConfiguration

str = userBean

str = userConfiguration

str = userController

str = userDao

str = userService

str = myBean

由输出可以清楚的看到,上述定义的五个类成功被@ComponentScan 扫描到,并在程序启动的时候进行加载。

3. @Configuration 和 Environment

​ @Configuration 通常和Environment 一起使用,通过@Environment 解析的属性驻留在一个或多个"属性源"对象中,@Configuration类可以使用@PropertySource,像Environment 对象提供属性源

为了便于测试,我们引入junit4和spring-test 的依赖,完整的配置文件如下

<?xml version="1.0"encoding="UTF-8"?>4.0.0org.springframework.bootspring-boot-starter-parent2.1.5.RELEASE<!-- lookup parent from repository -->com.spring.configurationspring-configuration0.0.1-SNAPSHOTspring-configurationDemo project for Spring Boot1.85.0.6.RELEASE4.3.13.RELEASE4.12org.springframework.bootspring-boot-starter-testtestorg.springframeworkspring-context${spring.version}org.springframeworkspring-test${spring.test.version}junitjunit${junit.version}org.springframework.bootspring-boot-maven-plugin复制代码

在config 包下定义一个 EnvironmentConfig 类,注入Environment 属性,完整代码如下:

@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(classes = EnvironmentConfig.class)@Configuration@PropertySource("classpath:beanName.properties")publicclassEnvironmentConfig{@AutowiredEnvironment env;@TestpublicvoidtestReadProperty(){// 获取bean.name.controller 的属性System.out.println(env.getProperty("bean.name.controller"));// 判断是否包含bean.name.componentSystem.out.println(env.containsProperty("bean.name.component"));// 返回与给定键关联的属性值System.out.println(env.getRequiredProperty("bean.name.service"));    }}复制代码

在/resources 目录下新建beanName.properties 文件,如下:

bean.name.configuration=beanNameConfigurationbean.name.controller=beanNameControllerbean.name.service=beanNameServicebean.name.component=beanNameComponentbean.name.repository=beanNameRepository复制代码

启动并进行Junit测试,输出如下:

…..…...

beanNameController

true

beanNameService

…..…...

4. @Autowired 、 @Inject、@Resource 的区别

@Inject: 这是jsr330 的规范,通过AutowiredAnnotationBeanPostProcessor 类实现的依赖注入。位于javax.inject包内,是Java自带的注解。

@Inject@Named("environment")Environment env;

不加@Named注解,需要配置与变量名一致即可。

@Autowired: @Autowired 是Spring提供的注解,通过AutowiredAnnotationBeanPostProessor 类实现注入。位于org.springframework.beans.factory.annotation 包内,是Spring 中的注解

@AutowiredEnvironment env;

默认是通过byType 实现注入

@Resource: @Resource 是jsr250规范的实现,@Resource通过CommonAnnotationBeanPostProcessor 类实现注入。@Resource 一般会指定一个name属性,如下:

@Resource(name ="environment")Environment env;复制代码

默认是通过byName 实现注入

区别:

@Autowired和@Inject基本是一样的,因为两者都是使用AutowiredAnnotationBeanPostProcessor来处理依赖注入。但是@Resource是个例外,它使用的是CommonAnnotationBeanPostProcessor来处理依赖注入。当然,两者都是BeanPostProcessor。

在介绍完上述三者的区别之后,可以对Environment的属性以上述注入方式进行改造

@Value、@PropertySource 和 @Configuration

@Configuration 可以和@Value 和@PropertySource 一起使用读取外部配置文件,具体用法如下:

在config 包下新建一个ReadValueFromPropertySource类,代码如下

@PropertySource("classpath:beanName.properties")@ConfigurationpublicclassReadValueFromPropertySource{@Value("bean.name.component")    String beanName;@Bean("myTestBean")publicMyBeanmyBean(){returnnewMyBean(beanName);    }}

通过@PropertySource引入的配置文件,使@Value 能够获取到属性值,在给myBean()方法指定了一个名称叫做myTestBean。

修改MyBean类,增加一个name属性和一个构造器,再生成其toString() 方法

publicclassMyBean{    String name;publicMyBean(String name){this.name = name;    }publicMyBean(){        System.out.println("generate MyBean Instance");    }publicvoidinit(){        System.out.println("MyBean Resources Initialized");    }@OverridepublicStringtoString(){return"MyBean{"+"name='"+ name +'\''+'}';    }}

在SpringConfigurationApplication中进行测试,如下

publicclassSpringConfigurationApplication{publicstaticvoidmain(String[] args){// 为了展示配置文件的完整性,之前的代码没有删除。//        AnnotationConfigApplicationContext context = = new AnnotationConfigApplicationContext(MyConfiguration.class)//        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");//        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();//        context.register(MyConfiguration.class);//        context.refresh();////        // 获取启动过程中的bean 定义的名称//        for(String str : context.getBeanDefinitionNames()){//            System.out.println("str = " + str);//        }//        context.close();ApplicationContext context =newAnnotationConfigApplicationContext(ReadValueFromPropertySource.class);        MyBean myBean = (MyBean) context.getBean("myTestBean");        System.out.println("myBean = "+ myBean);    }}复制代码

使用Applicatio@InConntext 就能够获取myTestBean 这个bean,再生成myBean的实例。

输出:myBean = MyBean{name='bean.name.component'}

5. @Import 和 @Configuration

@Import的定义(来自于JavaDoc):表明一个或者多个配置类需要导入,提供与Spring XML中相等的功能,允许导入@Configuration 、@ImportSelector、@ImportBeanDefinitionRegistar的实现,以及常规组件类似于AnnotationConfigApplicationContext。可能用于类级别或者是原注解。如果XML或者其他非@Configuration标记的Bean资源需要被导入的话,使用@ImportResource。下面是一个示例代码:

在pojo 包下新建两个配置类,分别是CustomerBo, SchedualBo

@ConfigurationpublicclassCustomerBo{publicvoidprintMsg(String msg){        System.out.println("CustomerBo : "+ msg);    }@BeanpublicCustomerBotestCustomerBo(){returnnewCustomerBo();    }}@ConfigurationpublicclassSchedulerBo{publicvoidprintMsg(String msg){        System.out.println("SchedulerBo : "+ msg);    }@BeanpublicSchedulerBotestSchedulerBo(){returnnewSchedulerBo();    }}复制代码

在config 包下新建一个AppConfig,导入CustomerBo 和 SchedulerBo 。

@Configuration@Import(value = {CustomerBo.class,SchedulerBo.class})publicclassAppConfig{}

在config 包下新建一个ImportWithConfiguration ,用于测试@Import 和 @Configuration 的使用

publicclassImportWithConfiguration{publicstaticvoidmain(String[] args){        ApplicationContext context =newAnnotationConfigApplicationContext(AppConfig.class);        CustomerBo customerBo = (CustomerBo) context.getBean("testCustomerBo");        customerBo.printMsg("System out println('get from customerBo')");        SchedulerBo schedulerBo = (SchedulerBo) context.getBean("testSchedulerBo");        schedulerBo.printMsg("System out println('get from schedulerBo')");    }}

输出:

CustomerBo : System out println('get from customerBo')

SchedulerBo : System out println('get from schedulerBo')

@Profile

@Profile: 表示当一个或多个@Value 指定的配置文件处于可用状态时,组件符合注册条件,可以进行注册。

三种设置方式:

可以通过ConfigurableEnvironment.setActiveProfiles()以编程的方式激活

可以通过AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME (spring.profiles.active )属性设置为

JVM属性

作为环境变量,或作为web.xml 应用程序的Servlet 上下文参数。也可以通过@ActiveProfiles 注解在集成测试中以声明方式激活配置文件。

作用域

作为类级别的注释在任意类或者直接与@Component 进行关联,包括@Configuration 类

作为原注解,可以自定义注解

作为方法的注解作用在任何方法

注意:

​ 如果一个配置类使用了Profile 标签或者@Profile 作用在任何类中都必须进行启用才会生效,如果@Profile({"p1","!p2"}) 标识两个属性,那么p1 是启用状态 而p2 是非启用状态的。

6. @ImportResource 和 @Configuration

@ImportResource: 这个注解提供了与@Import 功能相似作用,通常与@Configuration 一起使用,通过AnnotationConfigApplicationContext 进行启动,下面以一个示例来看一下具体用法:

在config下新建TestService 类,声明一个构造函数,类初始化时调用

publicclassTestService{publicTestService(){        System.out.println("test @importResource success");    }}

在/resources 目录下新建 importResources.xml ,为了导入TestService

<?xml version="1.0"encoding="UTF-8"?>

      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd

      http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd

      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">复制代码

然后在config 下新建一个ImportResourceWithConfiguration, 用于读取配置文件

@Configuration@ImportResource("classpath:importResources.xml")publicclassImportResourceWithConfiguration{@AutowiredprivateTestService service;publicvoidgetImportResource(){newTestService();    }publicstaticvoidmain(String[] args){        AnnotationConfigApplicationContext context =newAnnotationConfigApplicationContext(ImportResourceWithConfiguration.class);        context.getBean("testService");    }}

输出:test @importResource success

7. @Configuration 嵌套

@Configuration注解作用在类上,就和普通类一样能够进行相互嵌套,定义内部类。

// 来自JavaDoc@ConfigurationpublicclassAppConfig{@InjectDataSource dataSource;@BeanpublicMyBeanmyBean(){returnnewMyBean(dataSource);  }@ConfigurationstaticclassDataConfig(){@BeanDataSourcedataSource(){returnnewEmbeddedDatabaseBuilder().build()    }  }}

在上述代码中,只需要在应用程序的上下文中注册 AppConfig 。由于是嵌套的@Configuration 类,DatabaseConfig 将自动注册。当AppConfig 、DatabaseConfig 之间的关系已经隐含清楚时,这就避免了使用@Import 注解的需要。

@Lazy 延迟初始化

@Lazy: 表明一个bean 是否延迟加载,可以作用在方法上,表示这个方法被延迟加载;可以作用在@Component (或者由@Component 作为原注解) 注释的类上,表明这个类中所有的bean 都被延迟加载。如果没有@Lazy注释,或者@Lazy 被设置为false,那么该bean 就会急切渴望被加载;除了上面两种作用域,@Lazy 还可以作用在@Autowired和@Inject注释的属性上,在这种情况下,它将为该字段创建一个惰性代理,作为使用ObjectFactory或Provider的默认方法。下面来演示一下:

修改MyConfiguration类,在该类上添加@Lazy 注解,新增一个IfLazyInit()方法,检验是否被初始化。

@Lazy@Configuration@ComponentScan(basePackages ="com.spring.configuration.pojo")publicclassMyConfiguration{@BeanpublicMyBeanmyBean(){        System.out.println("myBean Initialized");returnnewMyBean();    }@BeanpublicMyBeanIfLazyInit(){        System.out.println("initialized");returnnewMyBean();    }}复制代码

修改SpringConfigurationApplication 启动类,放开之前MyConfiguration 的启动类

publicclassSpringConfigurationApplication{publicstaticvoidmain(String[] args){        AnnotationConfigApplicationContext context =newAnnotationConfigApplicationContext(MyConfiguration.class);//        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");//        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();//        context.register(MyConfiguration.class);//        context.refresh();////        // 获取启动过程中的bean 定义的名称for(String str : context.getBeanDefinitionNames()){            System.out.println("str = "+ str);        }//        context.close();//        ApplicationContext context =//                new AnnotationConfigApplicationContext(ReadValueFromPropertySource.class);//        MyBean myBean = (MyBean) context.getBean("myTestBean");//        System.out.println("myBean = " + myBean);}}

输出你会发现没有关于bean的定义信息,但是当吧@Lazy 注释拿掉,你会发现输出了关于bean的初始化信息:

myBean Initialized

generate MyBean Instance

initialized

generate MyBean Instance

8. @RunWith 和 @ContextConfiguration

Junit4 测试类,用于注解在类上表示通过Junit4 进行测试,可以省略编写启动类代码,是ApplicationContext 等启动类的替换。一般用@RunWith 和 @Configuration 进行单元测试,这是软件开发过程中非常必要而且具有专业性的一部分,上面EnvironmentConfig类证实了这一点:

@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(classes = EnvironmentConfig.class)@Configuration@PropertySource("classpath:beanName.properties")publicclassEnvironmentConfig{//    @Autowired//    Environment env;@InjectEnvironment env;@TestpublicvoidtestReadProperty(){// 获取bean.name.controller 的属性System.out.println(env.getProperty("bean.name.controller"));// 判断是否包含bean.name.componentSystem.out.println(env.containsProperty("bean.name.component"));// 返回与给定键关联的属性值System.out.println(env.getRequiredProperty("bean.name.service"));    }}

9. @Enable 启动Spring内置功能

详情查阅@EnableAsync,@EnableScheduling,@EnableTransactionManagement,@EnableAspectJAutoProxy,@EnableWebMvc官方文档

10. @Configuration 使用约束

必须以类的方式提供(即不是从工厂方法返回的实例)

@Configuration 注解的类必须是非final的

配置类必须是非本地的(即可能不在方法中声明),native 标注的方法

任何嵌套的@Configuration 都必须是static 的。

@Bean 方法可能不会反过来创建更多配置类

COMSOL网格划分技巧总结 在对马赫曾德尔型光学传感器进行模拟仿真时,在采用自动物理场自动控制网格-极细化的情况下透射谱曲线仍不理想,因此需要手动划分网格来对其进行更精细的剖分。 手动划分的基本原则是在作用边界,热点,曲边处做细致划分, 基底,包层等做粗略划分。对于光波导型的微纳结构,在仿真时一般需要用到创建边界层网格。 1.COMSOL所需要的网格数量 网格单元数越多,结果精细度越高,计算所需内存越多。在细化到一定程度后网格收敛,仿真结果提升不明显。 2.网格剖分类型 ... 阅读详情

相关推荐

【遥感数字图像处理(朱文泉)】第一章 数字图像基础

关于图像的定义、类型、模拟图像和数字图像

甜子yu的博客 4406

spring的@ContextConfiguration注解

spring的@ContextConfiguration注解

听海边涛声 2137

从建模到调参:基于Simulink的两轮差速机器人轨迹跟踪PID控制全流程解析

本文详细解析了基于Simulink的两轮差速机器人轨迹跟踪PID控制全流程。从运动学建模入手,对比了基于距离与基于位置偏差的两种控制策略,并重点阐述了高精度轨迹跟踪的控制器设计、Simulink仿真搭建及PID参数整定方法,为移动机器人运动控制提供了完整的仿真实践指南。

weixin_29169505的博客 314

@ContextConfiguration的用法

@ContextConfiguration这个注解通常与@RunWith(SpringJUnit4ClassRunner.class)联合使用用来测试 当一个类添加了注解@Component,那么他就自动变成了一个bean,就不需要再Spring配置文件中显示的配置了。把这些bean收集起来通常有两种方式,Java的方式和XML的方式。当这些bean收集起来之后,当我们想要在某个测试类使用@Au...

Darcy的专栏 1万+

自建邮局服务器| 批量邮件群发系统PowerMTA+oem(mumara,mailwizz, interspire)

世界顶级自建邮局服务器PowerMTA+oem(mumara,mailwizz, interspire) PowerMTA4.5(最好用的 群发邮件软件)是用于大批量多ip开发的邮件传递邮寄。可按每小时发送数近百万条电子邮件,发送IP地址和域可以详细配置,加上目前流行前端oem,mumara,mailwizz, interspire等,可定时发送,定时重复发送,实现全自动化 邮件群发 方案。 官网(powermta4.5下载) https://www.sparkpost.com/powermta/ 使用Po

ytrsexpo的博客 6506

STM32异常与中断过程详解

1. 异常与中断概念引入 异常主要是指来自CPU内部的意外事件,比如执行了未定义指令、算术溢出、除零运算等发生在CPU内部的意外事件,这些异常的发生,会引起CPU运行相应的异常处理程序;中断一般来自硬件(如片上外设、外部I/O输入等)发生的事件,当这些硬件产生中断信号时,CPU会暂停当前运行的程序,转而去处理相关硬件的中断服务程序。但无论是异常还是中断,都会引起程序执行偏离正常的流程,转而去执行异常/中断的处理函数。 下面对异常和中断的介绍,如果中断信号的产生原因来自CPU内部,则称之为异常;如果中断信号来

luobeihai的博客 1万+

Spring入门

Spring Framework Spring Core IOC、AOP Spring Data Access Transactions、Spring Mybatis Web Servlet Spring MVC Integration Email、Scheduling、AMQP、Security Spring IOC Inversion of Control 控制反转,是一种面向对象编程的设计思想(减少beans的耦合度) Dependency Injection 依赖注入,是IOC思想的实现 IO

盏息的博客 1897

风控域——知识图谱相关原理

本文全面介绍了知识图谱在风控领域的应用原理。从基础知识入手,阐述了知识图谱的定义、概念及应用场景,重点聚焦于金融风控。进一步讲解了知识图谱的技术架构,涵盖计算、融合与构建等方面。深入探讨了知识表示、建模、抽取、挖掘、存储、融合、检索和推理等关键技术原理,并结合金融风控实际需求,详细说明了各技术环节的具体应用方法与流程,为构建高效风控知识图谱提供了理论与实践指导。

庄小焱 612

spring的@ContextConfiguration注解-java.lang.IllegalStateException: Failed to load ApplicationContext

spring的@ContextConfiguration注解问题描述:问题原因:@ContextConfiguration 注解的用法详解总结 近期项目由普通项目换成了gradle构建项目以及管理 问题描述: 在junit测试的时候出现: Failed to load ApplicationContext 具体如下 > Task :wrapper BUILD SUCCESSFUL in...

学无止境 1万+

高分SCI讨论部分必学AI写作套路!仅需五步结合GPT‑5辅助,让你的SCI论文更有说服力(附实用AI提示词)

对于很多写SCI论文的学术人来说,其实“讨论部分”才是最致命的,网上虽然有大量的写作技巧和模板提供参考,但往往让人眼花缭乱,还是不知道如何下手。即便是下手了,也很难兼顾学术性与可读性,实际上讨论部分的难点并不在于写,而在于你能研究结果说清楚。今天七哥教你借助GPT-5,用五步法结合精心设计的AI提示词,让你能在科学逻辑与语言表达上一次性解决“讨论部分”的结构、内容、润色和翻译问题,轻松写出符合高分SCI期刊要求的讨论段落。

智能AI让学术科研更容易 1334

【网络与爬虫 41】TLS指纹伪造技术深度解析:ja3、ja4反检测与绕过策略

TLS指纹是现代反爬虫系统的重要检测手段,通过分析客户端TLS握手特征来识别爬虫。本文将深入解析ja3、ja4等TLS指纹技术原理,详细介绍指纹伪造和绕过策略,通过实际代码示例和工具使用,帮助开发者掌握TLS指纹反检测技术,构建更隐蔽的网络爬虫系统。

熵数实验室 1万+

@ContextConfiguration注解说明

学习spring实战中相关的单元测试 1 正常使用 @ContextConfiguration Spring整合JUnit4测试时,使用注解引入多个配置文件 1.1 单个文件 @ContextConfiguration(locations="../applicationContext.xml") @ContextConfiguration(classes = SimpleConfiguratio...

3万+

使用ArcGIS Pro进行土地利用分类的机器学习与深度学习

传统的土地利用分类方法通常依赖于手动解译和规则定义,但随着机器学习和深度学习的发展,我们现在可以利用这些技术来自动化和提高分类的精度。ArcGIS Pro是一种功能强大的GIS软件,它提供了丰富的工具和功能,可以支持土地利用分类的机器学习和深度学习。我们将首先讨论数据准备和预处理的步骤,然后介绍常用的机器学习和深度学习方法,并提供相应的源代码示例。这可以通过人工标注或半自动的方式完成。数据裁剪:根据研究区域的范围,裁剪遥感影像数据,以减少计算和存储的负担,并确保只包含感兴趣的土地利用区域。

code_program481的博客 2043

我被面试官给虐懵了,竟然是因为我不懂Spring中的@Configuration

作者 l cxuan来源 l Hollis(ID:hollischuang)现在大部分的Spring项目都采用了基于注解的配置,采用了@Configuration 替换标签的做法。一行简...

磊哥聊Java 330

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

原创 | 我被面试官给虐懵了,竟然是因为我不懂Spring中的@Configuration

△Hollis, 一个对Coding有着独特追求的人△这是Hollis的第216篇原创分享作者 l cxuan来源 l Hollis(ID:hollischuang)...

HollisChuang's Blog 2014

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

@configuration注解_我被面试官给虐懵了,竟然是因为我不懂Spring中的@Configuration...

现在大部分的Spring项目都采用了基于注解的配置,采用了@Configuration 替换标签的做法。一行简单的注解就可以解决很多事情。但是,其实每一个注解背后都有很多值得学习和思考的内容。这些思考的点也是很多大厂面试官喜欢问的内容。在一次关于Spring注解的面试中,可能会经历面试官的一段夺命连环问:@Configuration有什么用?@Configuration和XML有什么区别?哪种好?...

weixin_39982452的博客 196

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

面试官问Spring Boot 最核心的三个注解时,我懵了

最近面试一些 Java 开发者,他们其中有些在公司实际用过 Spring Boot, 有些是自己兴趣爱好在业余自己学习过。 然而,当我问他们 Spring Boot 最核心的 3 个注解是什么,令我失望的是鲜有人能答上来,这样你能说你对 Spring Boot 很了解吗?这可能还会给你减分! Spring Boot 核心注解讲解 Spring Boot 最大的特点是无需 XML 配置文件,能...

360linker 4849
上一篇: 如何写优雅的SQL原生语句?
下一篇: 面试官们“爱不释手”的分布式系统架构到底是个什么鬼?
加班不秃顶
博客等级 码龄7年 1822粉丝 599原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值