1注解与xml的相应说明
@EnableConfigurationProperties: 配置@ConfigurationProperties使用,在@EnableConfigurationProperties写入class名称,然后class中写入@ConfigurationProperties
@SpringBootApplication:springboot的核心注解,目的是开启自动配置
@PropertySource:指定加载配置文件
@Configuration: 等价于<Beans></Beans>。用于定义配置类,可替换xml配置文件,被注解的类内部包含有一个或多个被@Bean注解的方法,这些方法将会被AnnotationConfigApplicationContext或AnnotationConfigWebApplicationContext类进行扫描,并用于构建bean定义,初始化Spring容器。
@Bean:等价于<Bean></Bean>
@ComponentScan:指定范围 等价于<context:component-scan base-package=”com.item.demo”/>
@ConfigurationProperties: 主要用来把properties配置文件转化为bean(类)来使用的
1.1@Configuration @Bean beans bean
<?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" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd" default-lazy-init="false"> <bean id="student" class="domain.Student"> <property name="id" value="11"/> <property name="age" value="22"/> <property name="name" value="jack"/> </bean> //扫描 com.item.demo包下所有的 带注解的文件 <context:component-scan base-package=”com.item.demo”/> </beans>
1.2需要导入的依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> </dependency>
2四类主键类型注解
@Component:组件注解,通用注解,被该注解描述的类将被loC容器管理并实例化,以下三个都是主键注解的细化,当不确当用哪一个时候,就可以用这个。
@Controller:语义注解,说明当前类是MVC应用中的控制器类。
@Service:语义注解,说明当前类是Service业务服务类。
@Repository:语义注解,说明当前类用于业务持久层通常描述对应Dao类。