这篇文章主要介绍了Spring Boot注解学习(一)要点,非常不错,具有参考借鉴价值,需要的朋友参考下吧
声明bean的注解:
@Component组件,没有明确角色的bean
@Service,在业务逻辑层(service)中使用
@Repository,在数据访问层(dao)中使用
@Controller,在展现层中使用
@Configuration声明配置类
实体类无需添加注解,因为并不需要“注入”实体类
指定Bean的作用域的注解:
@Scope("prototype")
默认值为singleton
可选值prototype、request、session、globalSession
声明生成Bean的方法的注解:
@Bean 用在方法上,告诉Spring容器,你可以从下面这个方法中拿到一个Bean
使用AnnotationApplicationContext对象的getBean方法获取Bean
注入Bean的注解:
@Autowired,自动注入(默认为byType型的注入),可以用在属性或者方法上,可以通过设置required = "false"说明不要求一定要注入有多个同样的接口的实现时,通过@qualifier区分
当注入的变量为List后者Map时,会把所有的接口实现都注入进来,key为Bean的名字,value为实现类对象。可以通过在实现类上添加@order=1来指定加载顺序,数越小越优先加载
@Lazy启动延迟注入
配置类注解:
@Configuration声明当前类是一个配置类,相当于Spring配置的一个xml文件
@ComponentScan,自动扫描配置类所在包名下的所有bean
@EnableAutoConfiguration,启动自动配置
在spring boot中这三个注解可以用一个@SpringBootApplication替代
@EnableTransactionManagement,开启事务支持
事务管理:
@EnableTransactionManagement,加在配置类中,开启事务支持
@Transactional,加在Service的方法上,标注需要事务支持
AOP注解:
@AspectJ
任务调度:
@Scheduled用在需要定时执行的方法上 @EnableScheduling用在需要使用的入口类上
Spring MVC集成:
首先需要对Application类进行修改
@SpringBootApplication @EnableTransactionManagement //1、添加继承SpringBootServletInitializer public class Application extends SpringBootServletInitializer{ public static void main(String[] args) { SpringApplication.run(Application.class, args); } @Override //2、重写configure方法 protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return super.configure(builder); } } Spring MVC的注解: @Controller,在展现层使用 @ResponseBody @RestController
【相关推荐】
1. 特别推荐:“php程序员工具箱”V0.1版本下载
2. Java免费视频教程
3. JAVA初级入门教程
以上是关于java注解Spring Boot的教学的详细内容。更多信息请关注PHP中文网其他相关文章!

JVM'SperformanceIsCompetitiveWithOtherRuntimes,operingabalanceOfspeed,安全性和生产性。1)JVMUSESJITCOMPILATIONFORDYNAMICOPTIMIZAIZATIONS.2)c提供NativePernativePerformanceButlanceButlactsjvm'ssafetyFeatures.3)

JavaachievesPlatFormIndependencEthroughTheJavavIrtualMachine(JVM),允许CodeTorunonAnyPlatFormWithAjvm.1)codeisscompiledIntobytecode,notmachine-specificodificcode.2)bytecodeisisteredbytheybytheybytheybythejvm,enablingcross-platerssectectectectectross-eenablingcrossectectectectectection.2)

TheJVMisanabstractcomputingmachinecrucialforrunningJavaprogramsduetoitsplatform-independentarchitecture.Itincludes:1)ClassLoaderforloadingclasses,2)RuntimeDataAreafordatastorage,3)ExecutionEnginewithInterpreter,JITCompiler,andGarbageCollectorforbytec

JVMhasacloserelationshipwiththeOSasittranslatesJavabytecodeintomachine-specificinstructions,managesmemory,andhandlesgarbagecollection.ThisrelationshipallowsJavatorunonvariousOSenvironments,butitalsopresentschallengeslikedifferentJVMbehaviorsandOS-spe

Java实现“一次编写,到处运行”通过编译成字节码并在Java虚拟机(JVM)上运行。1)编写Java代码并编译成字节码。2)字节码在任何安装了JVM的平台上运行。3)使用Java原生接口(JNI)处理平台特定功能。尽管存在挑战,如JVM一致性和平台特定库的使用,但WORA大大提高了开发效率和部署灵活性。

JavaachievesPlatFormIndependencethroughTheJavavIrtualMachine(JVM),允许Codetorunondifferentoperatingsystemsswithoutmodification.thejvmcompilesjavacodeintoplatform-interploplatform-interpectentbybyteentbytybyteentbybytecode,whatittheninternterninterpretsandectectececutesoneonthepecificos,atrafficteyos,Afferctinginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginging

JavaispoperfulduetoitsplatFormitiondence,对象与偏见,RichstandardLibrary,PerformanceCapabilities和StrongsecurityFeatures.1)Platform-dimplighandependectionceallowsenceallowsenceallowsenceallowsencationSapplicationStornanyDevicesupportingJava.2)

Java的顶级功能包括:1)面向对象编程,支持多态性,提升代码的灵活性和可维护性;2)异常处理机制,通过try-catch-finally块提高代码的鲁棒性;3)垃圾回收,简化内存管理;4)泛型,增强类型安全性;5)ambda表达式和函数式编程,使代码更简洁和表达性强;6)丰富的标准库,提供优化过的数据结构和算法。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

Atom编辑器mac版下载
最流行的的开源编辑器

WebStorm Mac版
好用的JavaScript开发工具

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

Dreamweaver Mac版
视觉化网页开发工具

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。