Chaos-woo / lifeshow-server

毕设代码备份。短视频小程序服务端,包含管理端和小程序后端(SpringBoot项目)
2 stars 1 forks source link

关于@Value("${minip.access}") @Value("${minip.access.now}") 参数注入失败问题 #3

Open liuxin303 opened 2 years ago

liuxin303 commented 2 years ago

尊敬的作者您好: 我是一个在学习springboot的新手,我在idea打包你的项目时,出现了一些问题,minip.access,minip.access.now 这两个参数并未在application.yml,application-dev.yml以及application-pro.yml中定义,所以报错,错误如下:

Test set: per.chao.lifeshow.LifeshowApplicationTests

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 12.637 s <<< FAILURE! - in per.chao.lifeshow.LifeshowApplicationTests contextLoads Time elapsed: 0.003 s <<< ERROR! java.lang.IllegalStateException: Failed to load ApplicationContext Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'statService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'statServiceImpl': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'minip.access' in value "${minip.access}" Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'statServiceImpl': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'minip.access' in value "${minip.access}" Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'minip.access' in value "${minip.access}"

如果可以的话可以修复这个问题吗?

Chaos-woo commented 2 years ago

这个是一个用户访问量的统计,主要是用来后台系统统计用户登录次数统计的(没做单个用户的登录去重)

访问量统计

minip_access: 'minip.access'

访问量统计

minip_access_now: 'minip.access.now' 上面是我的配置配置,你可以看下

几个用到这个配置的类是 MiniProgramAccessInitializer(部署服务的时候会把redis里面的数据初始化一下) ScheduledTask#accessNumDailyToZero() (每天零点的时候会把当天的用户访问数清零,总访问数量不清) UserController#code2Session()和UserController#getUserId两个接口会用到StatServiceImpl类下的incrAccess方法会把redis中这两个配置的值+1

你可以自己随意命名,只用增加配置文件里面改这两个配置的值就行 minip.access: 'minip_access(只是redis的key,可以随意命名)' minip.access.now: 'minip_access_now(只是redis的key,可以随意命名)'

您可以先处理一下,之后我再重新提交修复这个问题