# study-cloud **Repository Path**: zsljava/study-cloud ## Basic Information - **Project Name**: study-cloud - **Description**: springCloud 学习 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2017-03-14 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # SpringCloud ## 使用方法 启动顺序 cloud-eureka-server //服务注册、发现中心 cloud-config-server //配置文件服务中心 cloud-user-service //用户服务中心 cloud-zuul-server //网关配置中心 ## SpringCloud 常用的注解 @Controller 控制层,里面有多个连接 @Service 业务层,一般对于接口和实现 @Qualifier 如果一个接口有多个实现,那么注入时候加上唯一标示 @Repository 一般的dao层 @Autowired 自动注入依赖 @RequestMapping (value='',method={RequestMethod。GET或者POSt})绑定url @RequestParam (value='' required=false)绑定参数 @ModelAttribute 一般用于controller层,呗注解的方法会在所以mapping执行之前执行,并且可以绑定参数到Model model里面。 @Transactional (readOnly=true)注解式事务 @Value(“${}”)可以注入properties里面的配置项 @ControllerAdvice 是spring3提供的新注解,控制器增 @ExceptionHandler 如果在controller方法遇到异常,就会调用含有此注解的方法。 @InitBinder 一般用于controller 可以将所以form 讲所有传递进来的string 进行html编码,防止xss攻击,比如可以将字符串类型的日期转换成date类型 @EnableCaching 注解自动化配置合适的缓存管理器。 @EnableWebSecurity 注解开启spring security的功能,集成websercrityconfigureadapter。 @SpringBootApplication相当于@configuration,@EnableAutoConfiguation @ComponentScan三个注解合用。 @EnableDiscoveryclient 自定义服务发现的客服端 @EnableAdminServer 使用admin监控应用。 @EnableEurekaClient配置本应用将使用服务注册和服务发现,注意:注册和发现用这个注解。 @EnableHystrix表示启动断路器,断路器依赖于服务注册和发现。 @HystrixCommand注解方法失败后,系统将西东切换到fallbackMethod方法执行, @EnableHystrixDashboard 表示启动对hystrix的监控 @EnableCircuitBreaker或者 @EnableHystrix 表明Spring boot工程启用hystrix,两个注解是等价的 @EnableAutoConfiguration spring boot自动配置,尝试根据你添加的jar依赖自动配置你的spring应用。 @ComponentScan 表示将该类自动发现并注册bean 可以自动收集所有的spring组件 @Comfiguration 相当于传统的xml配置文件 @Import 导入其他配置类 @ImportResource用来 加载xml配置文件 @FeignClient注解中的fallbank属性指定回调类 @RestController是@controller和@ResponseBody的结合体 ## 当前已知问题 config-server 配置信息需要加密(相关文档中有资料,可以直接http://host:port/encrypt/加密内容) zuul中需要对ribbon.eureka.enabled设置true/false 如果为true则可以通过eureka的serverId去自动找寻服务,不用硬编码 使用zuul后,项目刚刚启动后第一次访问会出现timeout问题 ## 文档资料 [SpringCloud中文文档](https://springcloud.cc/spring-cloud-netflix-zhcn.html) [SpringCloud ConfigServer 加密](http://www.itmuch.com/spring-cloud/config-server-encrypt-decrypt/) [Mybatis 代码生成器](http://www.studyjava.cn/topic/view/8a9a158e95414edc81fb88c9b3ffeef6.html) [在线REST接口调试工具](http://apizza.cc/)