Spring 注解学习笔记
- @Component : 组件,没有明确的角色
- @Service : 在业务逻辑层(service层)使用
- @Repository : 在数据访问层(dao层)使用.
- @Controller : 在展现层(MVC--SpringMVC)使用
- @Aautowired : Spring提供的注解.
- @Inject : JSR-330提供的注解
- @Resource : JSR-250提供的注解
- @Configuration : 声明当前类是个配置类,相当于一个Spring配置的xml文件.
- @ComponentScan (cn.test.demo): 自动扫描包名下所有使用 @Component @Service @Repository @Controller 的类,并注册为Bean
- @WiselyConfiguration : 组合注解 可以替代 @Configuration和@ComponentScan
- @Bean : 注解在方法上,声明当前方法的返回值为一个Bean.
- @Bean(initMethod="aa",destroyMethod="bb")--> 指定 aa和bb方法在构造之后.Bean销毁之前执行.
- @Aspect : 声明这是一个切面
- @After @Before. @Around 定义切面,可以直接将拦截规则(切入点 PointCut)作为参数
- @PointCut : 专门定义拦截规则 然后在 @After @Before. @Around 中调用
- @Transcational : 事务处理
- @Cacheable : 数据缓存
- @EnableAaspectJAutoProxy : 开启Spring 对 这个切面(Aspect )的支持
- @Target (ElementType.TYPE):元注解,用来指定注解修饰类的那个成员 -->指定拦截规则
- @Retention(RetentionPolicy.RUNTIME)
- --->当定义的注解的@Retention为RUNTIME时,才能够通过运行时的反射机制来处理注解.-->指定拦截规则
- @import :导入配置类
- @Scope : 新建Bean的实例 @Scope("prototype") 声明Scope 为 Prototype
- @Value : 属性注入
- @Value ("我爱你") --> 普通字符串注入
- @Value ("#{systemProperties['os.name']}") -->注入操作系统属性
- @Value ("#{ T (java.lang.Math).random() * 100.0 }") --> 注入表达式结果
- @Value ("#{demoService.another}") --> 注入其他Bean属性
- @Value ( "classpath:com/wisely/highlight_spring4/ch2/el/test.txt" ) --> 注入文件资源
- @Value ("http://www.baidu.com")-->注入网址资源
- @Value ("${book.name}" ) --> 注入配置文件 注意: 使用的是$ 而不是 #
- @PostConstruct : 在构造函数执行完之后执行
- @PreDestroy : 在 Bean 销毁之前执行
- @ActiveProfiles : 用来声明活动的 profile
- @profile: 为不同环境下使用不同的配置提供了支持
- @Profile("dev") .......对方法名为 dev-xxxx的方法提供实例化Bean
- @EnableAsync : 开启异步任务的支持(多线程)
- @Asyns : 声明这是一个异步任务,可以在类级别 和方法级别声明.
- @EnableScheduling : 开启对计划任务的支持(定时器)
- @Scheduled : 声明这是一个计划任务 支持多种计划任务,包含 cron. fixDelay fixRate
- @Scheduled (dixedDelay = 5000) 通过注解 定时更新
- @Conditional : 条件注解,根据满足某一特定条件创建一个特定的Bean
- @ContextConfiguration : 加载配置文件
- @ContextConfiguration(classes = {TestConfig.class})
- @ContextConfiguration用来加载ApplicationContext
- classes属性用来加载配置类
- @WebAppCofiguration : 指定加载 ApplicationContext是一个WebApplicationContext
- @EnableAsync : 开启异步任务的支持(多线程)
- @EnableScheduling : 开启对计划任务的支持(定时器)
- @EnableWebMVC : 开启对Web MVC 的配置支持
- @EnableAaspectJAutoProxy : 开启Spring 对 这个切面(Aspect )的支持
- @EnableConfigurationProperties 开启对@ConfigurationProperties注解配置Bean的支持
- @EnableJpaRepositories : 开启对Spring Data JAP Repository 的支持
- @EnableTransactionManagement 开启对注解式事物的支持
- @EnableCaching开启注解是缓存的支持.
- @EnableDiscoveryClient 让服务发现服务器,使用服务器.Spring cloud 实现服务发现
- @EnableEurekaServer 注册服务器 spring cloud 实现服务注册@
- @EnableScheduling 让spring可以进行任务调度,功能类似于spring.xml文件中的命名空间<task:*>
- @EnableCaching 开启Cache缓存支持;
- @Controller : 注解在类上 声明这个类是springmvc里的Controller,将其声明为一个spring的Bean.
- @RequestMapping :可以注解在类上和方法上 映射WEB请求(访问路径和参数)
- @RequestMapping(value= "/convert",produces+{"application/x-wisely"}) 设置访问URL 返回值类型
- @ResponseBody : 支持将返回值放入response体内 而不是返回一个页面(返回的是一个组数据)
- @RequestBody : 允许request的参数在request体中,而不是直接连接在地址后面 次注解放置在参数前
- @Path Variable : 用来接收路径参数 如/test/001,001为参数,次注解放置在参数前
- @RestController : @Controller + @ResponseBody 组合注解
- @ControllerAdvice : 通过@ControllerAdvice可以将对已控制器的全局配置放置在同一个位置
- @ExceptionHandler : 用于全局处理控制器的异常
- @ExceptionHandier(value=Exception.class) -->通过value属性可过滤拦截器条件,拦截所有的异常
- @InitBinder : 用来设置WebDataBinder , WebDataBinder用来自动绑定前台请求参数到Model中.
- @ModelAttrbuute : 绑定键值对到Model中,
- @RunWith : 运行器
- @RunWith(JUnit4.class)就是指用JUnit4来运行
- @RunWith(SpringJUnit4ClassRunner.class),让测试运行于Spring测试环境
- @RunWith(Suite.class)的话就是一套测试集合,
- @WebAppConfiguration("src/main/resources") : 注解在类上,用来声明加载的ApplicationContex 是一个WebApplicationContext ,它的属性指定的是Web资源的位置,默认为
src/main/webapp ,自定义修改为 resource - @Before : 在 xxx 前初始化
- @SpringBootApplication : 是Spring Boot 项目的核心注解 主要目的是开启自动配置
- @SpringBootApplication注解是一个组合注解,主要组合了@Configuration .+@EnableAutoConfiguration.+@ComponentScan
- @Value : 属性注入,读取properties或者 Yml 文件中的属性
- @ConfigurationProperties : 将properties属性和一个Bean及其属性关联,从而实现类型安全的配置
- @ConfigurationProperties(prefix = "author",locations = {"classpath:config/author.properties"})
- 通过@ConfigurationProperties加载配置,通过prefix属性指定配置前缀,通过location指定配置文件位置
- @EnableAutoConfiguration 注解:作用在于让 Spring Boot 根据应用所声明的依赖来对 Spring 框架进行自动配置
这个注解告诉Spring Boot根据添加的jar依赖猜测你想如何配置Spring。由于spring-boot-starter-web添加了Tomcat和Spring MVC,所以auto-configuration将假定你正在开发一个web应用并相应地对Spring进行设置。 - @ Configuration @EnableAutoConfiguration
(exclude={xxxx.class}) 禁用特定的自动配置 - @SpringBootApplication 注解等价于以默认属性使用
@Configuration,@EnableAutoConfiguration和 @ComponentScan。
- @SuppressWarnings("unchecked")
- 告诉编译器忽略 unchecked 警告信息,如使用 list ArrayList等未进行参数化产生的警告信息
- @SuppressWarnings("serial")
- 如
果编译器出现这样的警告信息: The serializable class WmailCalendar does not declare a
static final serialVersionUID field of type long 使用这个注释将警告信息去掉。
- 如
- @SuppressWarnings("deprecation")
- 如果使用了使用@Deprecated注释的方法,编译器将出现警告信息。使用这个注释将警告信息去掉。
- @SuppressWarnings("unchecked", "deprecation")
- 告诉编译器同时忽略unchecked和deprecation的警告信息。
- @SuppressWarnings(value={"unchecked", "deprecation"})
- 等同于@SuppressWarnings("unchecked", "deprecation")
|
@Entity
@Table(name =
"S_PRODUCEINFO" ) @Data
@NoArgsConstructor
@AllArgsConstructor
public
class ProduceInfoEntity { @Id
@Column(name
= "app_name", unique = true, length = 50) private
String name; @Column(name
= "status") @Enumerated(EnumType.
STRING) private
ProduceStatus status; @Column(name
= "create_time", updatable = false) @Temporal(TemporalType.
TIMESTAMP) @CreationTimestamp
private
Date createTime; @Column(name
= "update_time") @Temporal(TemporalType.
TIMESTAMP) @UpdateTimestamp
private
Date updateTime; |
"S_PRODUCEINFO"
) : 表名为 "S_PRODUCEINFO"
"app_name", unique =
true, length = 50) :对应数据库字段,属性
STRING) : 采用枚举值类型和数据库字段进行交互
@Enumerted(EnumType.DATE) 获取年月日 yyyy-MM-dd
@Enumerted(EnumType.TIME)
获取时分秒 HH:MM:SS
Spring 注解学习笔记的更多相关文章
- Spring注解学习笔记一
一.Retention注解Retention(保留)注解说明,这种类型的注解会被保留到那个阶段. 有三个值: 1.RetentionPolicy.SOURCE —— 这种类型的Annotations只 ...
- Spring MVC 学习笔记一 HelloWorld
Spring MVC 学习笔记一 HelloWorld Spring MVC 的使用可以按照以下步骤进行(使用Eclipse): 加入JAR包 在web.xml中配置DispatcherServlet ...
- SpringBoot + Spring Security 学习笔记(五)实现短信验证码+登录功能
在 Spring Security 中基于表单的认证模式,默认就是密码帐号登录认证,那么对于短信验证码+登录的方式,Spring Security 没有现成的接口可以使用,所以需要自己的封装一个类似的 ...
- Spring Boot学习笔记2——基本使用之最佳实践[z]
前言 在上一篇文章Spring Boot 学习笔记1——初体验之3分钟启动你的Web应用已经对Spring Boot的基本体系与基本使用进行了学习,本文主要目的是更加进一步的来说明对于Spring B ...
- Spring框架学习笔记(5)——Spring Boot创建与使用
Spring Boot可以更为方便地搭建一个Web系统,之后服务器上部署也较为方便 创建Spring boot项目 1. 使用IDEA创建项目 2. 修改groupid和artifact 3. 一路n ...
- Spring框架学习笔记(8)——spring boot+mybatis plus+mysql项目环境搭建
之前写的那篇Spring框架学习笔记(5)--Spring Boot创建与使用,发现有多小细节没有提及,,正好现在又学习了mybatis plus这款框架,打算重新整理一遍,并将细节说清楚 1.通过I ...
- Spring Boot 学习笔记(六) 整合 RESTful 参数传递
Spring Boot 学习笔记 源码地址 Spring Boot 学习笔记(一) hello world Spring Boot 学习笔记(二) 整合 log4j2 Spring Boot 学习笔记 ...
- Spring框架学习笔记(1)
Spring 框架学习笔记(1) 一.简介 Rod Johnson(spring之父) Spring是分层的Java SE/EE应用 full-stack(服务端的全栈)轻量级(跟EJB比)开源框架, ...
- 转-Spring 注解学习手札(七) 补遗——@ResponseBody,@RequestBody,@PathVariable
转-http://snowolf.iteye.com/blog/1628861/ Spring 注解学习手札(七) 补遗——@ResponseBody,@RequestBody,@PathVariab ...
随机推荐
- C语言——什么是指针?
去年学C语言课时,初步了解了指针的概念,能看懂一些简单的含有指针的程序,但事实上对于指针并没有真正的弄明白它的使用,这点我在半年后的数据结构课程上才深刻的体会到和别人的差距.更加可怕的是,对于当时所得 ...
- spring的bean管理(注解和配置文件混合使用)
1.建三个类,在一个类中引用其他两个类 import javax.annotation.Resource; import org.springframework.beans.factory.annot ...
- Linux USB 驱动开发(一)—— USB设备基础概念【转】
本文转载自:http://blog.csdn.net/zqixiao_09/article/details/50984074 在终端用户看来,USB设备为主机提供了多种多样的附加功能,如文件传输,声音 ...
- Configure environment variables for different tools in jenkins
安装以下的工具,并在Jenkins中的Manage Jenkins-->Configure System-->Global Properties-->Environment Vari ...
- nyoj--635--Oh, my goddess(dfs)
Oh, my goddess 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Shining Knight is the embodiment of justice an ...
- nyoj--106--背包问题(贪心,水题)
背包问题 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 现在有很多物品(它们是可以分割的),我们知道它们每个物品的单位重量的价值v和重量w(1<=v,w<= ...
- 【POJ 3696】 The Luckiest number
[题目链接] http://poj.org/problem?id=3696 [算法] 设需要x个8 那么,这个数可以表示为 : 8(10^x - 1) / 9, 由题, L | 8(10^x - 1) ...
- TensorFlow——分布式的TensorFlow运行环境
当我们在大型的数据集上面进行深度学习的训练时,往往需要大量的运行资源,而且还要花费大量时间才能完成训练. 1.分布式TensorFlow的角色与原理 在分布式的TensorFlow中的角色分配如下: ...
- 跨域解决方案之JSONP,通过借助调用百度搜索的API了解跨域案例
跨域解决方案之JSONP 同源策略 同源策略(Same origin policy)是一种约定,它是浏览器最核心也最基本的安全功能,如果缺少了同源策略,则浏览器的正常功能可能都会受到影响.可以说Web ...
- Mysql数据类型(二)
字符类型 #官网:https://dev.mysql.com/doc/refman/5.7/en/char.html #注意:char和varchar括号内的参数指的都是字符的长度 #char类型:定 ...