how2j.cn

下载区
文件名 文件大小
请先登录 386k
增值内容 386k
386k

6分9秒
本视频采用html5方式播放,如无法正常播放,请将浏览器升级至最新版本,推荐火狐,chrome,360浏览器。 如果装有迅雷,播放视频呈现直接下载状态,请调整 迅雷系统设置-基本设置-启动-监视全部浏览器 (去掉这个选项)。 chrome 的 视频下载插件会影响播放,如 IDM 等,请关闭或者切换其他浏览器

步骤 1 : 先运行,看到效果,再学习   
步骤 2 : 模仿和排错   
步骤 3 : 拓扑图点亮   
步骤 4 : 创建子模块   
步骤 5 : pom.xml   
步骤 6 : application.yml   
步骤 7 : IpConfiguration   
步骤 8 : RedisCacheConfig   
步骤 9 : IndexData   
步骤 10 : IndexDataService   
步骤 11 : IndexDataController   
步骤 12 : IndexDataApplication   

步骤 1 :

先运行,看到效果,再学习

edit
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,378个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
先运行,看到效果,再学习
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,378个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,378个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
拓扑图点亮
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,378个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
创建子模块
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,378个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
<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> <parent> <groupId>cn.how2j.trend</groupId> <artifactId>trendParentProject</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <groupId>cn.how2j.trend</groupId> <artifactId>index-data-service</artifactId> <dependencies> <!-- springboot web --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- eureka-client --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <!-- redis --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> </dependencies> </project>
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,378个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/ spring: application: name: index-data-service
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
spring:
  application:
    name: index-data-service
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,378个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package cn.how2j.trend.config; import org.springframework.boot.web.context.WebServerInitializedEvent; import org.springframework.context.ApplicationListener; import org.springframework.stereotype.Component; @Component public class IpConfiguration implements ApplicationListener<WebServerInitializedEvent> { private int serverPort; @Override public void onApplicationEvent(WebServerInitializedEvent event) { this.serverPort = event.getWebServer().getPort(); } public int getPort() { return this.serverPort; } }
package cn.how2j.trend.config;
 
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
 
@Component
public class IpConfiguration implements ApplicationListener<WebServerInitializedEvent> {
 
    private int serverPort;
 
    @Override
    public void onApplicationEvent(WebServerInitializedEvent event) {
        this.serverPort = event.getWebServer().getPort();
    }
 
    public int getPort() {
        return this.serverPort;
    }
}
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,378个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package cn.how2j.trend.config; import java.time.Duration; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.cache.CacheManager; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.cache.RedisCacheConfiguration; import org.springframework.data.redis.cache.RedisCacheManager; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.RedisSerializationContext; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.databind.ObjectMapper; @Configuration @ConfigurationProperties(prefix = "spring.cache.redis") public class RedisCacheConfig { private Duration timeToLive = Duration.ZERO; public void setTimeToLive(Duration timeToLive) { this.timeToLive = timeToLive; } @Bean public CacheManager cacheManager(RedisConnectionFactory factory) { RedisSerializer<String> redisSerializer = new StringRedisSerializer(); Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class); //解决查询缓存转换异常的问题 ObjectMapper om = new ObjectMapper(); om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.PUBLIC_ONLY); om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); jackson2JsonRedisSerializer.setObjectMapper(om); // 配置序列化(解决乱码的问题) RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig() .entryTtl(timeToLive) .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer)) .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jackson2JsonRedisSerializer)) .disableCachingNullValues(); RedisCacheManager cacheManager = RedisCacheManager.builder(factory) .cacheDefaults(config) .build(); return cacheManager; } }
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,378个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package cn.how2j.trend.pojo; public class IndexData { String date; float closePoint; public String getDate() { return date; } public void setDate(String date) { this.date = date; } public float getClosePoint() { return closePoint; } public void setClosePoint(float closePoint) { this.closePoint = closePoint; } }
package cn.how2j.trend.pojo;

public class IndexData {

	String date;
	float closePoint;
	public String getDate() {
		return date;
	}
	public void setDate(String date) {
		this.date = date;
	}
	public float getClosePoint() {
		return closePoint;
	}
	public void setClosePoint(float closePoint) {
		this.closePoint = closePoint;
	}
	
}
步骤 10 :

IndexDataService

edit
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,378个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package cn.how2j.trend.service; import java.util.List; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import cn.how2j.trend.pojo.IndexData; import cn.hutool.core.collection.CollUtil; @Service @CacheConfig(cacheNames="index_datas") public class IndexDataService { @Cacheable(key="'indexData-code-'+ #p0") public List<IndexData> get(String code){ return CollUtil.toList(); } }
package cn.how2j.trend.service;

import java.util.List;

import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import cn.how2j.trend.pojo.IndexData;
import cn.hutool.core.collection.CollUtil;

@Service
@CacheConfig(cacheNames="index_datas")
public class IndexDataService {

    @Cacheable(key="'indexData-code-'+ #p0")
    public List<IndexData> get(String code){
    	return CollUtil.toList();
    }
}
步骤 11 :

IndexDataController

edit
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,378个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package cn.how2j.trend.web; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; import cn.how2j.trend.config.IpConfiguration; import cn.how2j.trend.pojo.IndexData; import cn.how2j.trend.service.IndexDataService; @RestController public class IndexDataController { @Autowired IndexDataService indexDataService; @Autowired IpConfiguration ipConfiguration; // http://127.0.0.1:8021/data/000300 @GetMapping("/data/{code}") public List<IndexData> get(@PathVariable("code") String code) throws Exception { System.out.println("current instance is :" + ipConfiguration.getPort()); return indexDataService.get(code); } }
步骤 12 :

IndexDataApplication

edit
增值内容,请先登录
完整的 SpringCloud 趋势量化投资项目,使用 Springboot 、Vue.js、redis, Zipkin, RabbitMQ, SpringCloud 等一整套技术栈, 从无到有涵盖全部59个知识点,378个开发步骤, 充实 SpringCloud 项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package cn.how2j.trend; import cn.hutool.core.convert.Convert; import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.util.NetUtil; import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.StrUtil; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import java.util.Scanner; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @SpringBootApplication @EnableEurekaClient @EnableCaching public class IndexDataApplication { public static void main(String[] args) { int port = 0; int defaultPort = 8021; int redisPort = 6379; int eurekaServerPort = 8761; if(NetUtil.isUsableLocalPort(eurekaServerPort)) { System.err.printf("检查到端口%d 未启用,判断 eureka 服务器没有启动,本服务无法使用,故退出%n", eurekaServerPort ); System.exit(1); } if(NetUtil.isUsableLocalPort(redisPort)) { System.err.printf("检查到端口%d 未启用,判断 redis 服务器没有启动,本服务无法使用,故退出%n", redisPort ); System.exit(1); } if(null!=args && 0!=args.length) { for (String arg : args) { if(arg.startsWith("port=")) { String strPort= StrUtil.subAfter(arg, "port=", true); if(NumberUtil.isNumber(strPort)) { port = Convert.toInt(strPort); } } } } if(0==port) { Future<Integer> future = ThreadUtil.execAsync(() ->{ int p = 0; System.out.printf("请于5秒钟内输入端口号, 推荐 %d ,超过5秒将默认使用 %d %n",defaultPort,defaultPort); Scanner scanner = new Scanner(System.in); while(true) { String strPort = scanner.nextLine(); if(!NumberUtil.isInteger(strPort)) { System.err.println("只能是数字"); continue; } else { p = Convert.toInt(strPort); scanner.close(); break; } } return p; }); try{ port=future.get(5,TimeUnit.SECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e){ port = defaultPort; } } if(!NetUtil.isUsableLocalPort(port)) { System.err.printf("端口%d被占用了,无法启动%n", port ); System.exit(1); } new SpringApplicationBuilder(IndexDataApplication.class).properties("server.port=" + port).run(args); } }


HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。


问答区域    
2020-09-24 输入其他端口号不行
mikedog777




为什么我输入别的端口不行的,之前还是可以的
加载中

							

							


1 个答案

how2j
答案时间:2020-09-29
根据你的提示信息是这个端口已经被占用了呀~



回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到





2020-07-12 @CrossOrigin
佛说

站长你好,我对这个项目中@CrossOrigin这个注解定义的地方不是很理解 1、跨域是指协议、域名、端口号有一个不满足即视为跨域吗? 2、关于indexCodeService、indexDataService和trendTradingBacktestService(以下简称backTestService)为什么(不)要加跨域 ①indexCodeService、backTestService和viewService已在注册中心注册,且通过网关管理 ②此时viewService的view.html在初始化时访问indexCodeService的控制器(即http://localhost:8031/api-view/===》http://localhost:8031/api-codes/codes); 这中被网关管理起来的微服务相互访问跨域吗?如果不算,为什么要在indexCodeService的控制器加上@CrossOrigin ③还是在viewService的view.html初始化的时候,会访问backTestService的控制器,而backTestService内部调用了indexDataService的控制器 (即http://localhost:8031/api-view/===》http://localhost:8021/data/{code}); 与viewService不同的是indexDataService是被通过feign访问 这个算跨域吗?我感觉这个算跨域,但实际上indexDataService的控制器并没有加上@CrossOrigin。难道是因为通过feign访问所以不算跨域吗 ④backTestService被调用逻辑同③,html初始化时调用backTestService的控制器 (即http://localhost:8031/api-view/===》http://localhost:8031/api-backtest/simulate/{code}/{startDate}/{endDate}); 疑问同②,是否算跨域,理由是什么




1 个答案

how2j
答案时间:2020-07-13
首先是跨域的定义,参考一下这篇文章呢,我觉得它讲得比较清楚: https://blog.csdn.net/qq_38128179/article/details/84956552 然后再是本项目的跨域,因为本项目是属于同一个机器,同一个ip,所以跨域略微特别,当是端口不同的时候算作是跨域了。



回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到




2020-07-06 同问 为什么IndexDataController 的方法上不加 允许跨域注解@CrossOrigin?
2019-12-30 如下
2019-12-24 这里为什么不加@CrossOrigin


提问太多,页面渲染太慢,为了加快渲染速度,本页最多只显示几条提问。还有 5 条以前的提问,请 点击查看

提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
关于 实践项目-趋势投资SpringCloud-指数数据微服务 的提问

尽量提供截图代码异常信息,有助于分析和解决问题。 也可进本站QQ群交流: 578362961
提问尽量提供完整的代码,环境描述,越是有利于问题的重现,您的问题越能更快得到解答。
对教程中代码有疑问,请提供是哪个步骤,哪一行有疑问,这样便于快速定位问题,提高问题得到解答的速度
在已经存在的几千个提问里,有相当大的比例,是因为使用了和站长不同版本的开发环境导致的,比如 jdk, eclpise, idea, mysql,tomcat 等等软件的版本不一致。
请使用和站长一样的版本,可以节约自己大量的学习时间。 站长把教学中用的软件版本整理了,都统一放在了这里, 方便大家下载: https://how2j.cn/k/helloworld/helloworld-version/1718.html

上传截图