【发布时间】:2019-11-15 13:13:31
【问题描述】:
我有 Spring Data Rest Application,我在其中创建了这样的投影
@Projection(name = "UserWithAvatar", types = { User.class })
public interface UserWithAvatar {
String getName();
String getEmail();
@Value("${app.url}/pictures/#{target.imageId}")
String getAvatar();
}
非工作部分是getAvatar,它会生成一个用于查看图片的url。
但是,此 ${app.url} 在投影中不起作用。
我如何在其中添加这个 application.properties 值?
【问题讨论】:
-
@Value("#{${app.url}/pictures/#{target.imageId}}")或类似的东西。 baeldung.com/spring-expression-language -
@AlanHay 我试过
@Value("#{ ${app.url} + '/pictures/' + target.imageId}"),不幸的是它没有用。然后它返回一个EL1041E: After parsing a valid expression, there is still more data in the expression: 'lcurly({)'错误。 -
@Deadpool 他们在投影中做docs.spring.io/spring-data/jpa/docs/current/reference/html/…
-
也许可以直接访问
systemProperties@Value("#{ systemProperties['app.url'] + '/pictures/' + target.imageId }")? -
@MartinBG 显然
application.properties值不在systemProperties中,或者您的示例中出现了其他问题。Property or field 'systemProperties' cannot be found on object of type 'org.springframework.data.projection.SpelEvaluatingMethodInterceptor$TargetWrapper' - maybe not public or not valid?
标签: spring spring-boot spring-data projection