spring自定义注解

SSM框架整合

吃可爱长大的小学妹 提交于 2020-01-14 01:03:37
昨夜有网友私信我说,希望我能写一篇关于SSM框架整合的博客 废话不多话,项目结构和配置文件如下(只提供基本配置,自定义配置还需自行配置),另外现在是自动配置时代,希望大家都能学习一下spring boot,我也写过很多spring boot的博客,未来我会继续从我的github上搬运 pom文件(如有需要自行添加): <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>BMS</groupId> <artifactId>BMS</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <name>BMS Maven Webapp</name> <!-- FIXME change it

java版spring cloud微服务架构b2b2c--Feign自定义注解翻译器

自作多情 提交于 2020-01-14 00:07:10
一 、新建自定义注解MyUrl了解springcloud架构可以加求求:三五三六二四七二五九 package org.crazyit.cloud.contract; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; //这个注解只能定义方法 @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface MyUrl { //为注解配置两个属性 String url(); String method(); } 二、 新建接口,使用MyUrl注解 package org.crazyit.cloud.contract; public interface ContractClient { @MyUrl(url = "/hello", method = "GET") public String hello(); } 三、 定义注解翻译器 package org.crazyit.cloud.contract; import

Spring 源码解析之DispatcherServlet源码解析(五)

放肆的年华 提交于 2020-01-13 06:23:14
spring 的 整个请求流程都是围绕着 DispatcherServlet 进行的 类结构图 根据类的结构来说 DispatcherServlet本身也是继承了HttpServlet的,所有的请求都是根据这一个Servlet来进行转发的 , 同时解释了为什么需要在web.xml进行如下配置 ,因为Spring是基于一个Servlet来展开的,当然不需要Servlet也能够使用Spring <servlet> <servlet-name>appServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/spring-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>appServlet</servlet-name> <url-pattern>/</url-pattern>

《熬夜吐血整理》近100道spring全家桶系列面试题整理【已完结!附答案文档】

社会主义新天地 提交于 2020-01-13 03:52:02
Spring 系列面试题整合 大家好,俺依旧是智慧与帅气并存的小木,今天给大家带来的是spring系列面试题完结篇 前言 终于!!! 功夫不负有心,历经3天时间 【加上熬夜四舍五入6天 [手动滑稽]】,小木这边把spring系列的面试题已经整理完毕了,得到了很多大佬的好评,我也是心生欢喜呀 同时也希望各位得到各位的支持,帮我点点赞好评一下是对我最大的支持 最近几天有很多朋友跟我聊到年后准备换工作跳槽,所以最近一段时间小木还是会照常更新面试知识点系列,这里已经把java岗位一写核心的知识点整理成了文档,希望大家加油!! 关于java核心知识点文档分享给大家 注:面试文档领取看文末 上上篇 — spring系列面试题整理题卡(1) 上篇 — spring boot,spring Cloud知识点整理(2) sping系列面试题展示 1、什么是spring? 2、使用Spring框架的好处是什么? 3、Spring由哪些模块组成? 4、核心容器(应用上下文) 模块 5、 BeanFactory – BeanFactory 实现举例 6、XMLBeanFactory 7、解释AOP模块 8、解释JDBC抽象和DAO模块 9、 解释对象/关系映射集成模块 10、解释WEB 模块 11、Spring配置文件 12、什么是Spring IOC 容器? 13、 IOC的优点是什么? 14、

SSM源码分析之Spring07-手写SpringV1.0

我是研究僧i 提交于 2020-01-12 19:25:57
目录导航 前言 手写SpringV1.0 准备工作 DispatchServlet实现Bean的定位、加载、注册 自定义注解 测试 后记 前言 《SSM源码分析之Spring05-DI实现原理(基于Annotation 注入)》 《SSM源码分析之Spring06-IOC 容器中那些鲜为人知的事儿》 前面的章节我们主要看了一下在spring源码是如何设计管理bean的。这节我们用简单的几个类实现一个核心的IOC功能~ 手写SpringV1.0 准备工作 我们首先整理一下思路: 然后,创建一个maven项目,最后的项目结构如下: pom.xml引入servlet依赖: < properties > <!-- dependency versions --> < servlet.api.version > 2.4 </ servlet.api.version > </ properties > < dependencies > <!-- requied start --> < dependency > < groupId > javax.servlet </ groupId > < artifactId > servlet-api </ artifactId > < version > ${servlet.api.version} </ version > < scope >

Spring aop 记录操作日志

心不动则不痛 提交于 2020-01-12 09:47:33
/** * 此为系统AOP切面的配置类 * 在spring-context.xml中引入些配置类 * @author Sai * @since 2016-11-15 */@Configuration@EnableAspectJAutoProxy(proxyTargetClass=true)//启用AspectJ自动代理@ComponentScan(basePackages = "com.bld.core.supervisor")//默认扫描与配置类相同的包下的@Component注解下的bean,想自动装配AOP切面,必需加上@Componentpublic class AopConfig { //显示装配切面的bean @Bean public UserAop userAop(){ return new UserAop(); } @Bean public SupervisorEventsAop supervisorEventsAop(){ return new SupervisorEventsAop(); } @Bean public CpsRewardCaculateAop cpsRewardCaculateAop(){ return new CpsRewardCaculateAop();}}在spring-context.xml中配置 <!-- 引入AOP切面配置类 -->

SpringBootTest 测试工具

家住魔仙堡 提交于 2020-01-11 04:58:50
以下内容,翻译自官方文档,并结合了学习过程的demo。 Spring Boot提供了许多实用程序和注解,帮助测试应用程序。测试支持由两个模块提供: spring-boot-test 包含核心项, spring-boot-test-autoconfigure 支持测试的自动配置。 大多数开发人员使用 spring-boot-starter-test ,它同时导入 SpringBoot 测试模块以及JUnit Jupiter、AssertJ、Hamcrest和许多其他有用的库。 此文使用当前最新稳定版本: SpringBoot 2.2.2.RELEASE 此 starter 还带来了 vintage 引擎,因此可以同时运行JUnit 4和JUnit 5测试。如果已经将测试迁移到JUnit5,那么应该排除JUnit4支持,如下例所示: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <exclusions> <exclusion> <!-- 此模块兼容junit4 和 junit 5,此示例直接使用 junit5 --> <groupId>org.junit.vintage</groupId> <artifactId

spring 启动过程

扶醉桌前 提交于 2020-01-11 01:48:17
首先,对于一个web应用,其部署在web容器中,web容器提供其一个全局的上下文环境,这个上下文就是ServletContext,其为后面的spring IoC容器提供宿主环境; 其次,在web.xml中会提供有contextLoaderListener。在web容器启动时,会触发容器初始化事件,此时contextLoaderListener会监听到这个事件,其contextInitialized方法会被调用,在这个方法中,spring会初始化一个启动上下文,这个上下文被称为根上下文,即WebApplicationContext,这是一个接口类,确切的说,其实际的实现类是XmlWebApplicationContext。这个就是spring的IoC容器,其对应的Bean定义的配置由web.xml中的context-param标签指定。在这个IoC容器初始化完毕后,spring以WebApplicationContext.ROOT WEB APPLICATION CONTEXT ATTRIBUTE为属性Key,将其存储到ServletContext中,便于获取; 再次,contextLoaderListener监听器初始化完毕后,开始初始化web.xml中配置的Servlet,这个servlet可以配置多个,以最常见的DispatcherServlet为例

SpringCache源码深度解析

早过忘川 提交于 2020-01-10 23:08:36
缓存是我们常用的一种优化系统的方案。 无论是前端缓存还是应用层缓存或者数据库缓存,其本质都是将查询过的数据缓存下来,下次再次查询该数据的时候如果数据没有过期,则直接返回缓存中该数据即可,不再执行查询操作。 SpringCache是我们常用的一种应用层缓存方案,其一般应用在方法上,下面我们先来看下具体的使用方式,然后再从源码角度分析其实现方案 1.SpringCache的使用 1)maven引入依赖 cache功能相关代码都在spring-context中,一般使用Spring的项目中都有该包,所以不用再单独引入 2)Service(业务处理类,代码参考网上文章,非原创,有改动) // 接口类 package cache; public interface IService { Account getAccountByName(String userName); void updateAccount(Account account); } // 实现类 public class AccountService implements IService{ @Override @Cacheable(value = "accountCache") // 使用了一个缓存名叫 accountCache public Account getAccountByName(String userName)

Spring 极速集成注解 redis 实践

隐身守侯 提交于 2020-01-10 13:58:00
Redis 做为基于内存的 Key-Value 数据库,用来做缓存服务器性价比相当高。 官方推出的面向 Java 的 Client Jedis,提供了很多接口和方法,可以让 Java 操作使用 Redis。 Spring 团队对 Jedis 进行了封装,独立为 spring-data-redis 项目,配合 spring 特性并集成 Jedis 的一些命令和方法。 本文重点描述集成过程,能让你迅速的通过 spring-data-redis 将 redis 集成到 spring 项目中,毕竟大家都忙的。 1. 添加项目依赖 <!--redis 缓存--> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-redis</artifactId> <version>1.8.4.RELEASE</version> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.9.0</version> </dependency> 2. 添加 spring-redis-context 配置 <?xml version="1.0"