【问题标题】:about spring social xml configuration关于spring social xml配置
【发布时间】:2012-05-11 16:48:18
【问题描述】:

我想知道配置中的“#{request.userPrincipal.name}”。当我运行我的春季社交项目时,它总是在“#{request.userPrincipal.name}”处出现错误,如果我设置一个诸如“123”之类的值,我的项目运行良好。出了什么问题,是否有任何其他配置而不是“#{request.userPrincipal.name}”?

<bean id="connectionRepository" factory-method="createConnectionRepository" factory-bean="usersConnectionRepository" scope="request">
    <constructor-arg value="#{request.userPrincipal.name}" />
    <aop:scoped-proxy proxy-target-class="false" />
</bean>

【问题讨论】:

  • 你得到的确切错误是什么?
  • @Seong 您是否尝试使用 props 文件填充 #{request.userPrincipal.name} 的值,如果是,那么我认为您应该使用 ${request.userPrincipal.name} ,而不是 $的 #
  • 是的,我想使用 ${request.userPrincipal.name} 但我不知道如何设置正确的值!它总是有这样的错误:org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 22): Field or property 'name' cannot be found on null

标签: spring spring-social


【解决方案1】:

这是一个Spring EL expression,意思是从Http请求中获取用户身份。应用自己的用户管理组件后,您可以用自己的方式替换 #{request.userPrincipal.name}

【讨论】:

  • 如何制作自己的用户管理组件并替换 #{request.userPrincipal.name} ???如果我想使用 #{request.userPrincipal.name} 我该怎么办?
  • @Seong 您可以使用现有框架来实现用户管理组件,例如使用 Spring 安全性。在最简单的形式中,您可以将用户身份绑定为 http 参数,例如,'example.com?username=foo',因此 #{request.username} 将等于 foo。
  • 但是 HttpServletRequest 没有 getUsername() 方法。所以 SpEL 无法从 request.username 获取值 -_-!
  • 对不起,我的错误。它应该是 #{request.getParameter('username')}
  • 谢谢,但我有另一个想法,即使用工厂 bean 生成 userId 并设置它^^您如何看待这个想法?
猜你喜欢
  • 2017-03-03
  • 2012-10-19
  • 1970-01-01
  • 2011-12-14
  • 1970-01-01
  • 2015-05-23
  • 2021-02-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多