LoginUserUtil 问题

来源:6-8 新增房源信息功能实现_下

慕函数4411803

2018-02-12

老师我下载了源代码仔细对照了,还是找不到问题,我的SecurityContextHolder.getContext().getAuthentication().getPrincipal()返回的一个String类型的用户名,跟老师的不一样,老师的直接就是User类型,是否是因为我用的Springboot是1.5.9版本的关系。我之前的问题也是getAuthentication可以返回值,但是principal就不可以,都只能返回String类型,没法得到User类型,强制转换也不行

我的代码里面session.SPRING_SECURITY_CONTEXT.authentication.principal返回的是登录用户名String类型,但是session.SPRING_SECURITY_CONTEXT.authentication.principal.username就提示org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'username' cannot be found on object of type 'java.lang.String' - maybe not public?


写回答

1回答

瓦力老师

2018-03-01

亲,不排除是版本依赖的问题,但是,瓦力这边怀疑更多的还是代码自身的问题,建议把课程源代码copy一份出来,看一下到底哪里是有问题的。祝亲学习愉快^)^

0
0

BAT大牛亲授 基于ElasticSearch的搜房网实战

ES+MySQL+Kafka,打造强力站内搜索

898 学习 · 285 问题

查看课程