From 1ae03ea2f7866b30796d7f8ae925c53d7d98c1b3 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 29 Mar 2019 16:21:42 +0300 Subject: Using @Resource where possible --- src/main/java/com/juick/server/api/Messages.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/main/java/com/juick/server/api') diff --git a/src/main/java/com/juick/server/api/Messages.java b/src/main/java/com/juick/server/api/Messages.java index 5c791df4..5a4d8c31 100644 --- a/src/main/java/com/juick/server/api/Messages.java +++ b/src/main/java/com/juick/server/api/Messages.java @@ -31,7 +31,9 @@ import com.juick.service.MessagesService; import com.juick.service.TagService; import com.juick.service.UserService; import org.apache.commons.io.IOUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationEventPublisher; +import org.springframework.core.io.Resource; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -67,6 +69,8 @@ public class Messages { private ApplicationEventPublisher applicationEventPublisher; @Inject private WebApp webApp; + @Value("classpath:Transparent.gif") + private Resource invisiblePixel; // TODO: serialize image urls @@ -204,8 +208,7 @@ public class Messages { userService.updateLastSeen(visitor); applicationEventPublisher.publishEvent( new MessageReadEvent(this, visitor, msg)); - return IOUtils.toByteArray( - Objects.requireNonNull(getClass().getClassLoader().getResource("Transparent.gif"))); + return IOUtils.toByteArray(invisiblePixel.getInputStream()); } throw new HttpBadRequestException(); } -- cgit v1.2.3