当前位置: 首页 > news >正文

Spring-注解编程

注解基础概念

1.什么是注解编程

指的是在类或者方法上加入特定的注解(@XXX) 完成特定功能的开发

@Component

public classXXX{}

 2.为什么要讲注解编程

1.注解开发方便

        代码简洁 开发速度大大提高

2.Spring开发潮流

    Spring2.x引入注解 Spring3.x完善注解 Springboot普及 推广注解编程

3.注解的作用

  • 替换XML这种配置形式,简化配置

  • 替换接口,实现调用双方的契约性

通过注解的方式,在功能调用者和功能提供者之间达成约定,进而进行功能的调用。因为注解应用更为方便灵活

4.Spring注解的发展历程

1.Spring2.x开始支持注解编程 @Componet @Service @Scope

        目的:提供这些注解只是为了在某些情况下简化XML的配置,作为XML开发的有益补充

2.Spring3.x @Configuration @Bean..

        目的:彻底替换XML,基于纯注解编程

3.Spring 4.x Springboot

       提倡使用注解常见开发

5.Spring注解开发的一个问题

Spring基于注解进行配置后,还能否解耦合呢?

Spring框架应用注解时,如果对注解配置的内容不满意,可以通过Spring配置文件进行覆盖

Spring基础注解(Spring2.x)

这个阶段注解 仅仅是简化XML配置 并不能完全替代XML

搭建开发环境

<context:compoent-scan base-package=""/>

作用:让Spring框架在设置包及其子包中扫描对应的注解 使其生效

 对象创建相关注解

@Component

作用:替换原有Spring配置文件中的<bean>标签

注意:

        id属性 component注解 提供了默认的设置方式 首单词首字母小写

        class属性 通过反射获得class内容

@Component细节
  • 如何显示指定工厂创建对象的id值

@Component("u")

  • Spring配置文件覆盖注解配置内容

applicationContext.xml

@Repository ---->XXXDAO

         @Repository

          public class UserDao{

}

@Service

        @Service

        public class UserService{

}

@Controller

        @Controller

        public class RegAction{

}

<bean id="和注解一致" class=""/>

id值  class的值 要和 注解中的设置保持一致

@Repository

@Service

@Controller

注解:本质上这些衍生注解就是@Component 

        作用<bean

        细节 @Service("s")

目的:更加准确的表达这一个类型的作用


注意:Spring整合Mybatis开发过程中 不使用@Repository @Component Dao的实现Spring创建了
 

  • @Scope注解

作用:控制简单对象创建次数
<bean id="" class="" scope="singleton/prototype"/>

 @Lazy注解

作用:延迟创建单例对象

一旦使用@Lazy注解后,Spring会在使用这个对象的时候,进行这个对象的创建

 注入相关注解

@Autowired

@Autowired细节分析

1.Autowired注解基于类型注入

        基于类型的注入:注入对象的类型,必须与目标成员变量类型想通过或者其子类(实现类)

2.Autowired Qualifier 基于名字进行注入(了解)

        基于名字的注入:注入对象的id值,必须与Qualifier注解中设置的名字相同

3.Autowired注解放置位置

        a)放置在对应成员变量的set方法上

        b)直接把这个注解放置在成员变量上,Spring通过反射直接对成员变量进行注入(赋值)推荐


4.javaEE规范中类似功能的注解

        JSR250 @Resource(name="userDAOImpl") 基于名字进行注入

        @Autowired()

        @Qualifier("userDAOImpl")

        注意:如果在应用Resource注解时,名字没有配对成功 那么会继续按照类型进行注入

        
 

 @Value注解

@Valye注解

1.设置 xxx.properties

        id=10

        name=gao

2.Spring工厂 读取这个配置文件

        <context:property-placeholder location=""/>

3.代码

        属性 @Value("${key}")

 @PropertySource

替换Spring配置文件中的<context:property-placeholder>标签

 @Value注解细节
  • @Value注解不能应用在静态成员变量上
  • @Value注解-properties 不能注入集合类型

注解扫描详解

<context:component-scan base-package="">

        <context:exclude-fliter type="" expression=""/>

       

</context component-scan>

当前包 及其子包


type:assignable 排除特定类型 不进行创建

type="annotation" 排除带@Service注解类型

type="aspectj" 切入点表达式 只能应用包切入点 类切入点

type ="regex" 正则表达式

type ="custom" 自定义排除策略

第三种常用
---可以多个叠加

 包含方式

基于注解开发的思考

配置互通

Spring注解配置 配置文件配置 互通

ref引用就是UserDaoImpl首字母小写创建的对象

 什么情况下使用注解 什么情况下使用配置文件

@Component 替换<bean

基础注解(@Componet @Autowired @Value) 程序员开发类型配置

1.程序员开发的类型上  可以加入对应注解 进行对象的创建
User UserService UserDao...

2应用其它非程序员开发的类型时,还是需要<bean 进行配置的

SqlSessionFactoryBean MapperScannerConfigrue

 Spring的高级注解(Spring3.x及以上)

1.配置Bean

Spring在3.x提供新的注解 用于替换XML配置文件

@Configuration

public class AppConfig{

}

 1.配置Bean 替换了XML的什么内容?

 2.AnnotationConfigApplicationContext

1.创建工厂代码

ApplicationContext ctx=new AnnotationConfigApplicationContext

2.指定配置文件

        1.指定配置bean的Class

        ApplicationContext ctx=new AnnotationConfigAplicationContext(AppConfig.class)

        2,指定配置bean所在的路径

        ApplicationContext ctx=new AnnotationConfigAplicationContext("包名");

 配置Bean开发的细节分析

引入配置文件log.propertities

@Configuration的本质

@Component的衍生注解


可以应用<context:component-scan 进行扫描

 2.@Bean注解

@Bean注解在配置bean中进行使用,等同于XML配置文件中的<bean>标签

 1.@Bean注解的基本使用

对象的创建     

1.简单对象

        直接通过new方式创建的对象

 User UserService UserDao

2.复杂对象

        不能通过new的方式直接创建的对象

        Connection SqlSessionFactory

public class AppConfig {@Beanpublic User user(){return new User();}/*创建一个复杂对象*/@Beanpublic Connection connection() throws ClassNotFoundException, SQLException {Class.forName("com.mysql.jdbc.Driver");Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sky_take_out?useSSL=false","root","123456");return connection;}
}
@Bean注解自定义id值
 @Bean("u")public User user(){return new User();}/*
@Bean控制对象的创建次数
@Bean("u")@Scope("singleton")public User user(){return new User();}
@Bean用户自定义类型注入
package annotationHigh;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class AppConfig1 {@Beanpublic User user(){return new User();}@Beanpublic UserDao userDao(){return new UserDaoImpl();}@Beanpublic UserService userService(UserDao userDao){UserServiceImpl userService = new UserServiceImpl();userService.setUserDao(userDao);return userService;}
//    @Bean
//    public UserService userService(){
//        UserServiceImpl userService = new UserServiceImpl();
//        userService.setUserDao(userDao());
//        return userService;
//    }
}
@Bean(JDK类型注入)

@BeanJDK类型注入细节分析 

如果直接在代码中进行set方法的调用 会存在耦合问题

package annotationHigh;import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;@Configuration
@PropertySource(value = "classpath:init.properties")
public class AppConfig1 {@Value("${id}")private Integer id;@Value("${name}")private String name;@Beanpublic User user(){return new User();}@Beanpublic UserDao userDao(){return new UserDaoImpl();}@Beanpublic UserService userService(UserDao userDao){UserServiceImpl userService = new UserServiceImpl();userService.setUserDao(userDao);return userService;}
//    @Bean
//    public UserService userService(){
//        UserServiceImpl userService = new UserServiceImpl();
//        userService.setUserDao(userDao());
//        return userService;
//    }@Beanpublic Customer customer(){Customer customer = new Customer();customer.setId(id);customer.setName(name);return customer;}
}

@ComponentScan注解

@ComponentScan注解在配置bean中进行使用,等同于XML配置文件中的<context:component-scan>标签


目的:进行相关注解的扫描:(@Component @Value ...@Autowired)

 基本使用

@Configuration
@ComponentScan(basePackages ="annontation")
public class AppConfig2 {
}
 排除、包含的使用

包含

Spring创建工厂的多种方式 

1.多种配置的应用场景

 2。配置优先级

@Component及其衍生注解<@Bean <配置文件bean标签

优先级高的配置 覆盖优先级低的配置
@Component

public class User{

}

@Bean

public User user(){

        return new User();

}

<bean id="user"class=""/>

注意:id值 应该保持一致

3.解决基于注解进行配置的耦合问题

@Configuration

//@ImportResources("applicationContext.xml")--------也会耦合

public class AppConfig4{

        @Bean

        public UserDao userDao(){

                return new UserDaoImpl();

        }

}


applicationContext.xml

<bean id="userDao" class=""/>

4.整合多个配置信息

为什么会有多个配置信息

拆分多个配置bean的开发,是一种模块化开发的形式,也体现了面向对象各司其职的设计思想

 5.多配置信息整合的方式

1.多个配置Bean的整合

2.配置Bean与@Component相关注解的整合

3.配置Bean与SpringXML配置文件的整合

整合洞中配置信息需要关注哪些要点

1.如何使多种配置信息 汇成一个整体

2.如何实现跨配置的注入

1.多个配置Bean的整合

base-package进行多个配置Bean的整合

 @Import

1.可以创建对象

2.多种配置bean的整合

 2.跨配置进行注入

在应用配置Bean的过程中,不管使用哪种方式进行配置信息的汇总,其操作方式都是通过成员变量加入@Autowired注解进行完成

 配置Bean与@Component相关注解的整合

 配置Bean与配置文件的整合

1.遗留系统的整合 2.配置覆盖

 配置Bean的底层实现原理

四维一体的开发思想 

1.什么是四维一体

Spring开发一个功能的4种形式,虽然开发方式不同,但最终效果是一样的

1.基于schema

2.基于特定功能注解

3.基于原始<bean

4.基于@Bean注解

2.四维一体的开发案例

1. <context:property-placeholder

<?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: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:property-placeholder location="classpath:init.properties"/><bean id="category" class="annontation.Category"></bean><context:component-scan base-package="annontation"></context:component-scan>
</beans>
package annontation;import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;//@Component
//@PropertySource(value = "classpath:init.properties")
public class Category {@Value("${id}")private Integer id;@Value("${name}")private String name;public Category() {}public Category(Integer id, String name) {this.id = id;this.name = name;}/*** 获取* @return id*/public Integer getId() {return id;}/*** 设置* @param id*/public void setId(Integer id) {this.id = id;}/*** 获取* @return name*/public String getName() {return name;}/*** 设置* @param name*/public void setName(String name) {this.name = name;}public String toString() {return "Categpry{id = " + id + ", name = " + name + "}";}
}

@PropertySource [推荐]

<?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: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:property-placeholder location="classpath:init.properties"/>-->
<!--    <bean id="category" class="annontation.Category"></bean>--><context:component-scan base-package="annontation"></context:component-scan>
</beans>
package annontation;import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;@Component
@PropertySource(value = "classpath:init.properties")
public class Category {@Value("${id}")private Integer id;@Value("${name}")private String name;public Category() {}public Category(Integer id, String name) {this.id = id;this.name = name;}/*** 获取* @return id*/public Integer getId() {return id;}/*** 设置* @param id*/public void setId(Integer id) {this.id = id;}/*** 获取* @return name*/public String getName() {return name;}/*** 设置* @param name*/public void setName(String name) {this.name = name;}public String toString() {return "Categpry{id = " + id + ", name = " + name + "}";}
}

<bean id="" class="PropertySourcePlaceholderCoonfigure"/>

<?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: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"><bean id="category" class="annontation.Category"></bean><bean id="propertyholder" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer"><property name="location" value="classpath:init.properties"></property></bean><context:component-scan base-package="annontation"></context:component-scan>
</beans>

@Bean  [推荐]
 

package annontation;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.io.ClassPathResource;@Configuration
@ComponentScan(basePackages = "annontation")
public class AppConfig6 {@Beanpublic PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();propertySourcesPlaceholderConfigurer.setLocations(new ClassPathResource("init.properties"));return propertySourcesPlaceholderConfigurer;}
}

纯注解AOP开发
package annontation;import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;@Configuration
@ComponentScan(basePackages = "annontation")
@EnableAspectJAutoProxy
public class AppConfig7 {
}
package annontation;import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;@Aspect
@Component
public class MyAspect {//切入点@Pointcut("execution(* *(..))")public void myPointcut(){};//切面@Around(value="myPointcut()")public Object around(ProceedingJoinPoint joinPoint) throws Throwable{System.out.println("before");Object ret=joinPoint.proceed();System.out.println("after");return ret;}
}

 细节分析

代理创建方式切换JDK Cglib

@EnableAspectjAutoProxy

切换为cglib

@EnableAspectJAutoProxy(proxyTargetClass = True)
纯注解版Spring+MyBatis整合

1.连接池

<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="url" value="jdbc:mysql://localhost:3306/db03?useSSL=false"/><property name="username" value="root"/><property name="password" value="123456"/><property name="driverClassName" value="com.mysql.jdbc.Driver"/>
</bean>

@Bean

public DruidDataSource dataSource(){

        DruidDataSource dataSource=new DruidDataSource();

        dataSource.setDriverClassName("");

        dataSource.setUrl();

        return dataSource;

}
2.SqlSessionFactoryBean

<!--    创建sqlSessionFactory SqlSessionFactoryBean--><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource"/><property name="mapperLocations"><list><value>classpath:mybatis.mapper/*Mapper.xml</value></list></property></bean>
@Bean
public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource){SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();sqlSessionFactoryBean.setDataSource(dataSource);sqlSessionFactoryBean.setMapperLocations(new ClassPathResource("mybatis.mapper/EmpMapper.xml"));return sqlSessionFactoryBean;
}

 编码

1.实体

2.表

3.Dao接口

4.Mapper文件

1. MapperLocations编码时通配写法

//设置Mapper文件路径

ResourcePatternResolver resolver=new PathMatchingResourcePatternResolver();
Resource[]resources=resolver.getResources("mybatis.mapper/*Mapper.xml");
sqlSessionFactoryBean.setMapperLocations(resources);
 2.配置Bean数据耦合的问题

package mybatis;import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;@Component
@PropertySource("classpath:mybatis.properties")
public class MybatisProperties {@Value("${mybatis.driverClassName}")private String driverClassName;@Value("${mybatis.url}")private String url;@Value("${mybatis.username}")private String username;@Value("${mybatis.password}")private String password;@Value("${mybatis.mapperLocations}")private String mapperLocations;public MybatisProperties() {}public MybatisProperties(String driverClassName, String url, String username, String password, String mapperLocations) {this.driverClassName = driverClassName;this.url = url;this.username = username;this.password = password;this.mapperLocations = mapperLocations;}/*** 获取* @return driverClassName*/public String getDriverClassName() {return driverClassName;}/*** 设置* @param driverClassName*/public void setDriverClassName(String driverClassName) {this.driverClassName = driverClassName;}/*** 获取* @return url*/public String getUrl() {return url;}/*** 设置* @param url*/public void setUrl(String url) {this.url = url;}/*** 获取* @return username*/public String getUsername() {return username;}/*** 设置* @param username*/public void setUsername(String username) {this.username = username;}/*** 获取* @return password*/public String getPassword() {return password;}/*** 设置* @param password*/public void setPassword(String password) {this.password = password;}/*** 获取* @return mapperLocations*/public String getMapperLocations() {return mapperLocations;}/*** 设置* @param mapperLocations*/public void setMapperLocations(String mapperLocations) {this.mapperLocations = mapperLocations;}public String toString() {return "MybatisProperties{driverClassName = " + driverClassName + ", url = " + url + ", username = " + username + ", password = " + password + ", mapperLocations = " + mapperLocations + "}";}
}
package mybatis;import com.alibaba.druid.pool.DruidDataSource;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;import javax.sql.DataSource;
import java.io.IOException;@Configuration
@ComponentScan("mybatis")
@MapperScan(basePackages = "mybatis")
public class MyBatisAutoConfiguration {@Autowiredprivate MybatisProperties mybatisProperties;@Beanpublic DataSource dataSource(){DruidDataSource dataSource = new DruidDataSource();dataSource.setDriverClassName(mybatisProperties.getDriverClassName());dataSource.setUrl(mybatisProperties.getUrl());dataSource.setPassword(mybatisProperties.getPassword());dataSource.setUsername(mybatisProperties.getUsername());return dataSource;}@Beanpublic SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource) throws IOException {SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();sqlSessionFactoryBean.setDataSource(dataSource);ResourcePatternResolver resolver=new PathMatchingResourcePatternResolver();Resource[]resources=resolver.getResources(mybatisProperties.getMapperLocations());sqlSessionFactoryBean.setMapperLocations(resources);return sqlSessionFactoryBean;}}

纯注解版本事务编程 

1.原始对象 XXX

<bean id="userService" class="xxx">

        <property name="userDao" ref="userDao">

@Service

public class UserServiceImpl implements UserService{

        @Autowired

        private UserDao userDao;

}

2.额外功能

<!----DataSourceTransactionManager>

        <bean id="dataSourceTransactionManager" class="org.spring.framework.jdbc.dataSource.DataSourceTransactionManager">

        <property name="dataSource" ref="dataSource">

</bean>
 

@Bean
public DataSourceTransactionManager dataSourceTransactionManager(){DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();dataSourceTransactionManager.setDataSource(dataSource);return dataSourceTransactionManager;
}

3.事务属性

        

@Transactional()
@Service
public class EmpServiceImpl implements EmpService{@Autowiredprivate EmpDao empDao;@Overridepublic void register(Emp emp) {empDao.add(emp);}
}

4.基于Schema的事务配置

<tx:annotation-driven transaction-manage="dataSourceTransactionManage"/>

@EnableTransactionManger--配置Bean

package mybatis;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;import javax.sql.DataSource;//Mybatis已经配置过扫描了
@Configuration
@EnableTransactionManagement
public class TransactionAutoConfiguration {//跨配置注入@Autowiredprivate DataSource dataSource;@Beanpublic DataSourceTransactionManager dataSourceTransactionManager(){DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();dataSourceTransactionManager.setDataSource(dataSource);return dataSourceTransactionManager;}
}

 Spring与YAML文件整合

1.什么是YML

YAML是一种新形式的配置文件,比XML更简单,比Properties更强大

 2.Properties进行配置问题

1.Properties表达过于繁琐,无法表达数据的内在联系

2.Properties无法表达对象 集合类型

3.YAML语法简洁

 1.定义yml文件

xxx.yml xxx.yaml

2.语法

  1.基本语法

        key:空格value

        name: suns

        password:123456

   2.对象概念

        account:

                id:1

                password:123456

    3.定义集合

        service

                -1111

                -2222

 4.Spring与YML集成思路分析

1.准备yml配置文件

        init.yml

        name: suns

        password: 123456

2.读取yml 转换成 Properties

        YamlPropertiesFactoryBean.setResources(yml配置文件路径) new ClassPathResources();

        YamlPropertiesFactoryBean.getObject()---->Properties

 3.应用PropertSourcePlaceholderConfigurer

        PropertySourcePlaceholderConfigurer.setProperties();

4.类中@Value注解注入

 5.Spring与YML集成编码

环境搭建

<dependency><groupId>org.yaml</groupId><artifactId>snakeyaml</artifactId><version>1.29</version>
</dependency>
最低版本1.18

编码 

1.准备yml配置文件

2.配置Bean中操作 完成YAML读取 与PropertySourcePlaceholderConfigure的创建

3.类 加入@Value注解

account:name: gaopassword: 123456
package yml;import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.io.ClassPathResource;import java.util.Properties;@Configuration
@ComponentScan(basePackages = "yml")
public class YmlAutoConfiguration {@Beanpublic PropertySourcesPlaceholderConfigurer propertySourcePlaceholderConfigurer() {YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();yamlPropertiesFactoryBean.setResources(new ClassPathResource("init.yml"));Properties properties = yamlPropertiesFactoryBean.getObject();PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();configurer.setProperties(properties);return configurer;}
}

 集成问题

1.集合处理问题

SpringEL表达式解决

@Value("#{'${list}'/split(',')}")

2.对象类型的YAML进行配置时 过于繁琐
@Value("${account.name}")

SpringBoot @ConfigurationProperties

相关文章:

Spring-注解编程

注解基础概念 1.什么是注解编程 指的是在类或者方法上加入特定的注解(XXX) 完成特定功能的开发 Component public classXXX{} 2.为什么要讲注解编程 1.注解开发方便 代码简洁 开发速度大大提高 2.Spring开发潮流 Spring2.x引入注解 Spring3.x完善注解 Springboot普及 推广注解…...

大数据学习栈记——MongoDB安装

本文介绍NoSQL技术&#xff1a;MongoDB的安装。操作系统&#xff1a;Ubuntu24.04 MongoDB介绍 MongoDB是一个基于分布式文件存储的数据库&#xff0c;由C语言编写&#xff0c;旨在为WEB应用提供可扩展的高性能数据存储解决方案。MongoDB是一个介于关系数据库和非关系数据库之…...

linux 系统编程基础部分 day1

常用指令 创建修改用户组 查看当前用户组&#xff1a;whoami 创建用户 sudo adduser 用户 sudo addgroup 组名 添加权限&#xff1a;chmod [u,g,o,a][x,w,r] 数字表示法r4 w2 x1 chmod 471 每个权限种类想加 给文件换所属用户 chown 新用户名 文件名 chgrp …...

访问不到服务器上启动的llamafactory-cli webui

采用SSH端口转发有效&#xff0c;在Windows上面进行访问 在服务器上启动 llamafactory-cli webui 后&#xff0c;访问方式需根据服务器类型和网络环境选择以下方案&#xff1a; 一、本地服务器&#xff08;物理机/虚拟机&#xff09; 1. 直接访问 若服务器与操作设备处于同一…...

论文阅读笔记——Generating Long Sequences with Sparse Transformers

Sparse Transformer 论文 解决了 Transformer 在长序列建模时的计算开销和内存过大的问题。 可视化了一个 128 层自注意力在 CIFAR-10 的数据集上学习到的注意力模式&#xff0c;发现&#xff1a;1&#xff09;稀疏性普遍存在&#xff1a;大多数层在多数数据点上表现出稀疏注意…...

【信息系统项目管理师】高分论文:论信息系统项目的整合管理(旅游景区导游管理平台)

更多内容请见: 备考信息系统项目管理师-专栏介绍和目录 文章目录 论文一、制定项目章程二、制订项目管理计划三、指导和管理项目工作四、管理项目知识五、监控项目工作六、实施整体变更控制七、结束项目或阶段论文 在国家《中国旅游“十三五”发展规划信息化专项规划的背景下…...

C++ 用红黑树封装map/set

前言 一、源码结构分析 二、模拟实现map/set 2.1 套上KeyOfT 2.2 普通迭代器实现 2.3 const迭代器实现 2.4 解决key不能修改的问题 2.5 map的[]实现 2.6 map/set以及红黑树源码 2.6.1 RBTree.h 2.6.2 set.h 2.6.3 map.h 总结 前言 之前的文章讲解了红黑树的具体实…...

VirtualBox虚拟机与主机之间无法复制粘贴的问题

插入出现问题&#xff0c;需要把其他的dvd弹出&#xff0c;比如系统安装镜像。 https://www.cnblogs.com/jianmuzi/p/17788084.html...

【HDFS入门】HDFS核心组件Secondary NameNode角色职责与运行机制解析

目录 1 Secondary NameNode的角色定位与常见误解 2 核心职责详解 2.1 核心功能职责 2.2 与NameNode的协作关系 3 运行机制深度剖析 3.1 检查点触发机制 3.2 元数据合并流程 4 与Hadoop 2.0 HA架构的对比 5 配置调优指南 5.1 关键配置参数 5.2 性能优化建议 6 实践应…...

AI知识补全(十六):A2A - 谷歌开源的agent通信协议是什么?

名人说&#xff1a;一笑出门去&#xff0c;千里落花风。——辛弃疾《水调歌头我饮不须劝》 创作者&#xff1a;Code_流苏(CSDN)&#xff08;一个喜欢古诗词和编程的Coder&#x1f60a;&#xff09; 上一篇&#xff1a;AI知识补全&#xff08;十五&#xff09;&#xff1a;AI可解…...

OOM问题排查和解决

问题 java.lang.OutOfMemoryError: Java heap space 排查 排查手段 jmap命令 jmap -dump,formatb,file<file-path> <pid> 比如 jmap -dump:formatb,file./heap.hprof 44532 使用JVisualVM工具&#xff1a; JVisualVM是一个图形界面工具&#xff0c;它可以帮…...

黑马头条day01

1)课程对比 2)项目概述 2.1)能让你收获什么 2.2)项目课程大纲 2.3)项目概述 随着智能手机的普及&#xff0c;人们更加习惯于通过手机来看新闻。由于生活节奏的加快&#xff0c;很多人只能利用碎片时间来获取信息&#xff0c;因此&#xff0c;对于移动资讯客户端的需求也越来越…...

关于IDEA中使用ctrl跳转源码出现???的解决方案

最近在学习大数据相关课程的时候使用ctrl查看源码时出现源码是问号的情况。写一篇博客来分享一下自己的解决方案&#xff1a; 但我使用ctrl查看源码的时候具体函数的细节使用???来代替&#xff0c;而且点击上方的Download按钮没有反应&#xff0c;这个时候我们需要手动指定…...

第三方API——Spring Boot 集成阿里云短信发送功能

目录 一. 创建阿里云OSS服务并获取密钥&#xff0c;开通短信服务 1.1 注册阿里云服务器 1.2 开通短信服务 1.3 创建对象存储OSS服务 1.4 RAM用户授权短信权限 1.5 新增用户并授权用户短信权限 1.6 获取 AccessKey ID 和 AccessKey Secret 二. 创建项目集成短信发送 2.1…...

【C++】前向声明(Forward Declaration)

前向声明&#xff08;Forward Declaration&#xff09;是在C、C等编程语言中&#xff0c;在使用一个类、结构体或其他类型之前&#xff0c;仅声明其名称而不给出完整定义的一种方式。 作用 减少编译依赖&#xff1a;当一个源文件包含大量头文件时&#xff0c;编译时间会显著增…...

Golang|抽奖相关

文章目录 抽奖核心算法生成抽奖大转盘抽奖接口实现 抽奖核心算法 我们可以根据 单商品库存量/总商品库存量 得到每个商品被抽中的概率&#xff0c;可以想象这样一条 0-1 的数轴&#xff0c;数轴上的每一段相当于一种商品&#xff0c;概率之和为1。 抽奖时&#xff0c;我们会生…...

10.第二阶段x64游戏实战-添加计时器

免责声明&#xff1a;内容仅供学习参考&#xff0c;请合法利用知识&#xff0c;禁止进行违法犯罪活动&#xff01; 本次游戏没法给 内容参考于&#xff1a;微尘网络安全 上一个内容&#xff1a;9.第二阶段x64游戏实战-创建项目代码获取人物属性 效果图&#xff1a; 当前游戏…...

fbx/obj/glb/gltf/b3dm等通用格式批量转换成osgb

fbx/obj/glb/gltf/b3dm等通用格式批量转换成osgb fbx/obj/glb/gltf/b3dm等通用格式批量转换成osgb...

打造AI应用基础设施:Milvus向量数据库部署与运维

目录 打造AI应用基础设施&#xff1a;Milvus向量数据库部署与运维1. Milvus介绍1.1 什么是向量数据库&#xff1f;1.2 Milvus主要特点 2. Milvus部署方案对比2.1 Milvus Lite2.2 Milvus Standalone2.3 Milvus Distributed2.4 部署方案对比表 3. Milvus部署操作命令实战3.1 Milv…...

使用WindSurf生成贪吃蛇小游戏:从零开始的开发之旅

在当今数字化时代&#xff0c;编程已经成为一项必备技能&#xff0c;而创建游戏无疑是学习编程过程中最具趣味性的项目之一。今天&#xff0c;我将向大家介绍如何使用WindSurf这款强大的代码生成工具来快速生成一个经典的贪吃蛇小游戏。从下载软件到运行游戏&#xff0c;我们将…...

论文学习:《EVlncRNA-net:一种双通道深度学习方法,用于对实验验证的lncRNA进行准确预测》

原文标题&#xff1a;EVlncRNA-net: A dual-channel deep learning approach for accurate prediction of experimentally validated lncRNAs 原文链接&#xff1a;https://www.sciencedirect.com/science/article/pii/S0141813025020896 长链非编码RNA( long non-coding RNAs&…...

LLM Post-Training

1. LLM的后训练分类 Fine-tuning Reinforcement Learning Test-time Scaling 方法 优点 缺点 Fine-tuning 任务适应性&#xff1a;能够针对特定任务或领域进行优化&#xff0c;提升模型在该任务上的性能。 数据驱动优化&#xff1a;利用标注数据直接调整模型参数&#x…...

【LLM】解锁Agent协作:深入了解谷歌 A2A 协议与 Python 实现

人工智能&#xff08;AI&#xff09;智能体正迅速成为企业提高生产力、自动化工作流程和增强运营能力的关键工具。从处理日常重复性任务到协助复杂的决策&#xff0c;智能体的潜力巨大。然而&#xff0c;当这些智能体来自不同的供应商、使用不同的框架或被限制在孤立的数据系统…...

FileWriter 详细解析与记忆方法

FileWriter 详细解析与记忆方法 一、FileWriter 核心概念 FileWriter 是 Java 中用于向文件写入字符数据的类&#xff0c;继承自 OutputStreamWriter&#xff0c;属于字符流体系。 1. 核心特点 特性说明继承关系Writer → OutputStreamWriter → FileWriter数据单位字符&am…...

Java笔记5——面向对象(下)

目录 一、抽象类和接口 1-1、抽象类&#xff08;包含抽象方法的类&#xff09; 1-2、接口 ​编辑​编辑 二、多态 ​编辑 1. 自动类型转换&#xff08;向上转型&#xff09; 示例&#xff1a; 注意&#xff1a; 2. 强制类型转换&#xff08;向下转型&#xff09; 示…...

c++------模板进阶

目录 一、模板 1.1 非类型模板参数 二、模板的特化 2.1 概念 2.2 函数模板特化 2.3 类模板特化 全特化 偏特化 &#xff08;1&#xff09;部分特化 &#xff08;2&#xff09;参数更进一步的限制 三、模板分离编译 3.1 什么是分离编译 3.2 模板的分离编译 3.3 解决…...

《轨道力学讲义》——第四讲:轨道计算与预测

第四讲&#xff1a;轨道计算与预测 引言 在轨道力学的研究中&#xff0c;轨道计算与预测是将理论付诸实践的关键环节。当我们掌握了轨道运动的基本规律和数学描述后&#xff0c;下一步便是要能够准确地计算航天器在任意时刻的位置和速度&#xff0c;并对其未来的运动轨迹进行…...

鸿蒙开发-页面跳转

1.路由使用 //1.引入路由 import router from ohos.router//2.使用跳转router.pushUrl({url: "pages/Show"})2.页面跳转 import { router } from kit.ArkUI;Entry Component struct LoginPage {State message: string 登陆页;build() {Row() {Column() {Text(this…...

数据大屏只能撑撑场面?

很多人对数据大屏的看法就是“没有用”、“花架子”&#xff0c;实际上&#xff0c;它的作用绝不止于此。 业财猫全新升级的经营驾舱模块&#xff0c;以精准的行业洞察与场景化设计&#xff0c;重新定义了这一工具的价值。 作为专为财税代账行业打造的一站式运营管理平台&…...

第十九讲 | XGBoost 与集成学习:精准高效的地学建模新范式

&#x1f7e8; 一、为什么要学习集成学习&#xff1f; 集成学习&#xff08;Ensemble Learning&#xff09; 是一种将多个弱学习器&#xff08;如决策树&#xff09;组合成一个强学习器的策略。它在地理学、生态学、遥感分类等领域表现尤为突出。 &#x1f4cc; 应用优势&#…...

大数据面试问答-批处理性能优化

1. 数据存储角度 1.1 存储优化 列式存储格式&#xff1a;使用Parquet/ORC代替CSV/JSON&#xff0c;减少I/O并提升压缩率。 df.write.parquet("hdfs://path/output.parquet")列式存储减少I/O的核心机制&#xff1a; 列裁剪&#xff08;Column Pruning&#xff09; …...

关于 软件开发模型 的分类、核心特点及详细对比分析,涵盖传统模型、迭代模型、敏捷模型等主流类型

以下是关于 软件开发模型 的分类、核心特点及详细对比分析&#xff0c;涵盖传统模型、迭代模型、敏捷模型等主流类型&#xff1a; 一、软件开发模型分类及核心特点 1. 瀑布模型&#xff08;Waterfall Model&#xff09; 核心特点&#xff1a; 线性阶段划分&#xff1a;需求分…...

【STL】set

在 C C C S T L STL STL 标准库中&#xff0c; s e t set set 是一个关联式容器&#xff0c;表示一个集合&#xff0c;用于存储唯一元素的容器。 s e t set set 中的元素会自动按照一定的顺序排序&#xff08;默认情况下是升序&#xff09;。这意味着在 s e t set set 中不能…...

信奥还能考吗?未来三年科技特长生政策变化

近年来&#xff0c;科技特长生已成为名校录取的“黄金敲门砖”。 从CSP-J/S到NOI&#xff0c;编程竞赛成绩直接关联升学优势。 未来三年&#xff0c;政策将如何调整&#xff1f;家长该如何提前布局&#xff1f; 一、科技特长生政策趋势&#xff1a;2025-2027关键变化 1. 竞…...

几何建模基础-拓扑命名实现及优化

1.背景介绍 1.1 什么是拓扑&#xff1f; 拓扑是研究几何图形或空间在连续改变形状后还能保持不变的一些性质的一个学科。它只考虑物体间的位置关系而不考虑它们的形状和大小。 Body对象的拓扑可以理解为面&#xff08;Face&#xff09;与边&#xff08;Edge&#xff09;、边…...

浙江大学DeepSeek系列专题线上公开课第二季第五期即将上线!deepseek音乐创作最强玩法来了!

浙江大学DeepSeek系列专题线上公开课第二季第5期即将在今晚进行直播&#xff01; 其中&#xff0c;今晚8点10分左右&#xff0c;浙大AI大佬张克俊教授将带来硬核的deepseek公开课讲座。 讲座 主题&#xff1a; 人工智能与音乐创作 主讲人&#xff1a; 张克俊 教授 人工智能作…...

electron-builder参数详解

electron-builder 是一个用于打包和构建 Electron 应用的工具&#xff0c;支持 macOS、Windows 和 Linux 平台&#xff0c;并提供了丰富的参数配置选项。 1、安装&#xff1a; npm install electron-builder --save-dev2、参数详解 命令&#xff1a; electron-builder build…...

PVE+CEPH+HA部署搭建测试

一、基本概念介绍 Proxmox VE ‌Proxmox Virtual Environment (Proxmox VE)‌ 是一款开源的虚拟化管理平台&#xff0c;基于 Debian Linux 开发&#xff0c;支持虚拟机和容器的混合部署。它提供基于 Web 的集中管理界面&#xff0c;简化了计算、存储和网络资源的配置与监控。P…...

Android Studio 日志系统详解

文章目录 一、Android 日志系统基础1. Log 类2. 日志级别 二、Android Studio 中的 Logcat1. 打开 Logcat2. Logcat 界面组成3. 常用 Logcat 命令 三、高级日志技巧1. 自定义日志工具类2. 打印方法调用栈3. 打印长日志4. JSON 和 XML 格式化输出 四、Logcat 高级功能1. 自定义日…...

【LLM】A2A 与 MCP:剖析 AI Agent 互联时代的两种关键协议

随着人工智能技术的飞速发展&#xff0c;AI Agent&#xff08;智能体&#xff09;正从理论走向实践&#xff0c;有望成为提升生产力的关键。然而&#xff0c;正如历史上任何新兴技术领域一样&#xff0c;标准的缺失导致了“筒仓效应”——不同来源、不同框架构建的 Agent 难以有…...

解析大尺寸液晶屏视觉检测,装配错位如何避免?

在3C电子产品种类飞速发展的今天&#xff0c;大尺寸液晶屏已成为市场主流&#xff0c;消费刚需。消费者对手机屏幕的视觉体验要求不断攀升&#xff0c;屏占比的提升成为各大手机厂商竞争的焦点。然而&#xff0c;大尺寸液晶屏在生产过程中面临着诸多检测难题&#xff0c;严重影…...

巴法云平台-TCP设备云-微信小程序实时接收显示数据-原理

微信小程序通过WebSocket或HTTP长轮询连接平台&#xff08;而非直接使用TCP&#xff09;&#xff01;&#xff01;&#xff01; 物联网平台对协议层的一种封装设计——将底层通信协议&#xff08;如TCP&#xff09;与应用层业务逻辑&#xff08;如主题路由&#xff09;解耦&am…...

ElementNotInteractableException原因及解决办法

在自动化测试中,ElementNotInteractableException是一个常见的异常,它通常发生在尝试与网页上的某个元素进行交互(例如点击、输入等操作)时,但由于该元素当前不可交互。这可能由多种原因引起,以下是一些常见的原因及其解决方法: 元素未完全加载 如果尝试与页面上的元素交…...

信息系统项目管理师-工具名词解释(上)

本文章记录学习过程中,重要的知识点,是否为重点的依据,来源于官方教材和历年考题,持续更新共勉 本文章记录学习过程中,重要的知识点,是否为重点的依据,来源于官方教材和历年考题,持续更新共勉 数据收集 头脑风暴 在短时间内获得大量创意,适用于团队环境,需要引导者…...

CSI-external-provisioner

main() 这段Go代码是一个CSI&#xff08;容器存储接口&#xff09;Provisioner&#xff08;供应器&#xff09;的实现&#xff0c;用于在Kubernetes集群中动态提供持久卷。代码涉及多个组件和步骤&#xff0c;下面是对关键部分的解释&#xff1a; 初始化和配置 命令行标志和…...

OpenAI为抢跑AI,安全底线成牺牲品?

几年前&#xff0c;如果你问任何一个AI从业者&#xff0c;安全测试需要多长时间&#xff0c;他们可能会淡定地告诉你&#xff1a;“至少几个月吧&#xff0c;毕竟这玩意儿可能改变世界&#xff0c;也可能毁了它。”而现在&#xff0c;OpenAI用实际行动给出了一个新答案——几天…...

单片机任意普通IO引脚使用定时器扩展外部中断的巧妙方法

在嵌入式系统中&#xff0c;将任意一个IO端口配置为外部中断源是一种常见的需求&#xff0c;尤其是在硬件资源有限的情况下。通过定时器扩展外部中断的方法&#xff0c;可以在不依赖专用中断引脚的情况下&#xff0c;实现对外部信号的实时响应。以下是一种基于定时器扩展外部中…...

arcgis几何与游标(1)

本节我们对几何进行展开学习 ArcPy 的几何对象 在 ArcPy 中&#xff0c;几何对象是表示地理空间数据的核心。它包括点&#xff08;Point&#xff09;、多点&#xff08;Multipoint&#xff09;、线&#xff08;Polyline&#xff09;和面&#xff08;Polygon&#xff09;等类型…...

安全密码处理实践

1. 引言 在现代应用程序中,密码存储和验证的安全性 直接关系到用户数据的保护。密码泄露事件频繁发生,通常是由于不安全的存储方式 或 弱加密处理 导致的。为了提高密码的安全性,开发者需要遵循一系列安全密码处理 的最佳实践。 本篇文章将详细介绍如何在应用程序中安全地…...

can‘t set boot order in virtualbox

Boot order setting is ignored if UEFI is enabled https://forums.virtualbox.org/viewtopic.php?t99121 如果勾选EFI boot order就是灰色的 传统BIOS就是可选的 然后选中任意介质&#xff0c;通过右边的上下箭头调节顺序&#xff0c;最上面的应该是优先级最高的 然后就…...