I have run into a very strange behavior with a spring-boot application. Under certain circumstances, our test build of the application will return results from the production database. The issue is not in the application.properties, otherwise it would ALWAYS return results from production. To track down the cause of this issue, I need to figure out some way to log what datasource the query is executing against.
If I have a CrudRepository like:
public interface MessageRepository extends CrudRepository<Message, Long> {
@Query("SELECT m from Message m WHERE m.status like :status AND m.createDate > :ago_X")
ArrayList<Message> findByStatusWithinLastXDays(@Param("status") String status, @Param("ago_X") LocalDateTime ago_X);
}
and a service class:
@Service
public class MessagesService {
private static final Logger logger = LoggerFactory.getLogger(MessagesService.class);
@Autowired
private MessageRepository messageRepository;
public ArrayList<Message> getMessagesWithStatus(String status, LocalDateTime dateXDaysAgo, String creatorAffiliation) {
return messageRepository.findByStatusWithinLastXDays(status, dateXDaysAgo);
}
}
how do I add logging to determine what datasource the query is being run on?