我有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值?
在@environment.getProperty('app.url')
块中使用#{}
。它适用于Spring Boot 2.3.0,我不确定较旧的版本。
示例:
@Value("#{target.pictureUrl ?: @environment.getProperty('app.url') + 'static/default-avatar.png'}")
String getAvatarUrl();