900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > Spring Framework 官方文档学习(一)介绍

Spring Framework 官方文档学习(一)介绍

时间:2022-11-06 13:24:03

相关推荐

Spring Framework 官方文档学习(一)介绍

http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#overview-maven-bom Spring框架提供了大概20个模块,分类为:Core Container,Data Access/Integration,Web,AOP (Aspect Oriented Programming),Instrumentation,Messaging, andTest。 1、Core Container包含:spring-core, spring-beans, spring-context, spring-context-support, and spring-expression 模块。 ①spring-core, spring-beans是Spring框架的基础,提供了IoC和DI功能。spring-beans中的BeanFactory是工厂模式的实现。 ②spring-context模块基于spring-core、spring-beans,是一种框架式访问对象的方法,类似JNDI注册方式。 还添加了国际化支持、事件传播支持、资源加载支持、上下文的创建支持等等。还有JavaEE的部分功能。 ApplicationContext接口是该模块的核心。 ③spring-context-support模块则提供了集成通用第三方库的支持,将其集成到Spring应用上下文中,如缓存、邮件、计划、模板引擎。 ④spring-expression模块提供了可在运行时查询和操作对象图的表达式语言,很强大。是对JSP中unified EL的扩展。 支持:设置/获取属性值,属性分配,方法调用,访问数组、集合及索引的内容,逻辑和数字运算符,命名变量,通过名字在Spring IoC容器中获取对象。 2、AOP and Instrumentation包含: ①spring-aop模块提供了AOP编程,允许定义方法拦截器和切入点,以与具体的功能代码解耦合。 ②spring-aspects模块集成了AspectJ。 ③spring-instrument模块,提供了类工具支持和类加载器实现,用于特定的应用服务器。 ④spring-instrument-tomcat模块,包含了对tomcat的代理。 3、MessagingSpring Framework 4 包含了spring-messaging模块,带有Spring Integration项目的关键抽象,如Message、MessageChannel、MessageHandler以及其他,以作为基于消息的应用的基础。 也提供了一些注解,可以将消息发送到方法中。 4、Data Access/Integration,包含JDBC、ORM、OXM、JMS和Transaction模块。 ①spring-jdbc模块,提供了JDBC抽象层,免除了繁杂的JDBC编码和不同数据库开发商错误代码的分析。 ②spring-tx模块,允许代码式和声明书事务管理。(需要实现特定接口,支持所有POJO??) ③spring-orm模块,提供了对常见ORM的集成层,常见ORM包括JPA、JDO和Hibernate。通过使用该模块,你既可以使用ORM的功能,也可以使用Spring提供的功能,例如简单的声明式事务管理。 ④spring-oxm模块,提供了抽象层,支持Object/XML映射实现 如JAXB、Castor、XMLBeans、JiBX和XStream。 ⑤spring-jms模块,包含了生产和消费消息功能,集成了spring-messaging模块。 5、Web,包含spring-web, spring-webmvc, spring-websocket, and springwebmvc-portlet模块。 ①spring-web模块,提供了基本的web功能,如文件上传、使用Servlet Listeners初始化IoC容器、web容器。同样包含了一个HTTP客户端和Spring远程支持的web部分。 ②spring-webmvc模块,包含了MVC和REST Web Service实现。 ③spring-webmvc-portlet模块,提供了用于Portlet环境的MVC实现,镜像了spring-webmvc模块的功能。 6、Testspring-test模块,支持Spring组件的单元测试和集成测试,使用JUnit或者TestUG。提供了Spring ApplicationContext的加载及缓存。还提供了mock对象! 技巧 通过使用Spring BOM,在dependencyManagement导入spring-framework-bom ,然后就可以保证所有的Spring依赖都是同一个版本 -- 可以不用再声明版本了。

<dependencyManagement><dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-framework-bom</artifactId><version>4.3.3.RELEASE</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId></dependency><dependencies>

Logging,这是Spring唯一强转要求的外部依赖,JCL。 关掉JCL:从spring-core模块中排除依赖。或者,选一个依赖取代JCL。

<dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>4.3.3.RELEASE</version><exclusions><exclusion><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId></exclusion></exclusions></dependency></dependencies>

至此,已经破坏了应用(不能运行了),所以还需要修复一下。使用JCL的其他实现例如SLF4J。

SLF4J,是编译时绑定,而不是运行时判断,所以更干净。(应该是指在编译时就判断是否需要相应的代码,不需要就去掉) 但是,有一些容器内置了JCL的实现,这时单纯的排除依赖是不够的。这时候最好的办法是反转类加载器层次,让应用控制JCL依赖,而非容器控制。(如IBM的WebSphere Application Server。知道就行,略过。) 4.0 版本的改进(摘录): 注入bean时,支持泛型限定。如@Autowired Repository<Customer> customerRepository。CGLIB-based proxy classes不再需要一个默认构造器。新的@RestController注解。4.1 版本的改进(摘录):

用Jackson支持JSONP。新的lifecycle,允许拦截@ResponseBody和@ResponseEntity方法,在controller返回之后,但写入响应之前。新的HttpMessageConverter选项:通过jackson-dataformat-xml扩展开启基于Jackson的XML序列化支持。如果存在jackson-dataformat-xml,将取代 JAXB2。4.2 版本的改进(摘录): 可以使用Java 8的默认方法来编写配置文件,@Bean默认方法。@Import支持导入常规类作为bean,而不仅仅是配置类了。内建的CORs支持,包含全局的(MVC Java config和 XML namespace)和局部的(如@CrossOrigin)配置。默认的JSON前缀,由"{} && "改成更安全的")]}', "。4.3 版本的改进(摘录): Java 8 的默认方法可以用作bean属性的GETTER/SETTER。如果目标bean只定义了一个构造方法,就不再需要@Autowired注解了。内建了对 HTTP HEAD and HTTP OPTIONS的支持。

@RequestMapping新的组合注解:@GetMapping,@PostMapping,@PutMapping,@DeleteMapping,and@PatchMapping

新的组合注解:@RequestScope,@SessionScope,and@ApplicationScope

新的@RestControllerAdvice注解。

新的@SessionAttribute和@RequestAttribute注解。

@

ModelAttributeallows preventing data binding viabinding=falseattribute (seereference).

@

PathVariablemay be declared as optional (for use on@ModelAttributemethods).

HTTP消息转换器中一致的charset处理,包括multipart文本内容默认的UTF-8编码。

静态资源处理使用配置好的ContentNegotiationManager,来决定媒体类型。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。