Category: Spring

Spring MongoDB query sorting

Query asked by user I’m fairly new on mongodb, and while I’m trying to make ordered mongodb query. But spring data mongodb’s sort method is deprecated. So I used org.springframework.data.domain.Sort: Query query = new Query(); query.with(new Sort(Sort.Direction.ASC,”pdate”)); return mongoTemplate.find(query, Product.class); I used this code block. But its not sorting the data. So can you prefer […]

Spring: Issue with passing Interface to controller constructor

Query asked by user Below is the problem I’m facing. While starting the dev tools I’m getting the below error Parameter 0 of constructor in tacos.web.DesignTacoController required a bean of type ‘tacos.data.IngredientRepository’ that could not be found. Action: Consider defining a bean of type ‘tacos.data.IngredientRepository’ in your configuration. Please help. IngredientRepository.java package tacos.data; import org.springframework.data.repository.CrudRepository; […]

Why Spring Boot 2.0 application does not run schema.sql?

Query asked by user While I was using Spring Boot 1.5, on application startup Hibernate executed schema.sql file located in /resources folder when appropriate configuration is set. After Spring Boot 2.0 release this feature does not work any more. I couldn’t find anything about this change in documentation. Here is my application.properties file content: spring.datasource.url=… […]

How to have Spring aspect support for repeatable annotation?

Query asked by user I have created a java 17 repeatable annotation and want to create an aspect around the method containing the annotation is invoked. This seems to work when method is annotated once but fails to invoke when I have repeatable annotation. I am using aspectjrt version 1.9.7. Am I doing something wrong […]

Is it possible to register with Container without using @Repository or @Bean?

Query asked by user public interface AccountRepository extends CrudRepository<AccountDBModel, Long> { @Modifying @Query(value = PortfolioQuery.ACCOUNT_INSERT) void insert(@Param(“exchangeId”) Long exchangeId, @Param(“name”) String name, @Param(“siteAccount”) String siteAccount, @Param(“memo”) String memo, @Param(“createdAt”) Long createdAt, @Param(“updatedAt”) Long updatedAt, @Param(“isActive”) Boolean isActive); @Modifying @Query(value = PortfolioQuery.ACCOUNT_UPDATE) void update(@Param(“id”) Long id, @Param(“exchangeId”) Long exchangeId, @Param(“name”) String name, @Param(“siteAccount”) String siteAccount, @Param(“memo”) […]

Bulk update with hibernate

Query asked by user Currently we have two endpoints in our API : One to update one entity An various ones to update one field of a Collection of entity The first one only use saveOrUpdate method of hibernate While the second one create a custom HQL query to update the desired field. I would […]

Aggregation Annotation Not Working It is Returning Empty

Query asked by user I am trying to make this Aggregation bellow using Spring Java, but it’s returning an Empty List on my console. This is working on MongoDB, but not on my spring application. This is my MongoDB Query: db.collection.aggregate([ { $match: { $and: [ { user_id: “256f5280-fb49-4ad6-b7f5-65c4329d46e0” }, { time: { $gte: 1622471890, […]

Error With ConfigurationPropertiesBinder java spring when trying to start application context

Query asked by user I have a simple application it fails to load with the below error APPLICATION FAILED TO START Description: An attempt was made to call a method that does not exist. The attempt was made from the following location: org.springframework.boot.context.properties.ConfigurationPropertiesBinder.register(ConfigurationPropertiesBinder.java:202) The following method did not exist: ‘org.springframework.beans.factory.support.BeanDefinitionBuilder org.springframework.beans.factory.support.BeanDefinitionBuilder.rootBeanDefinition(java.lang.Class, java.util.function.Supplier)’ The calling method’s […]

Spring Mvc integration test fails

Query asked by user I want to write an integration test for a delete method in my controller, but no matter how many times I tried rewriting it, I am still getting different errors. This is the method in my controller: @Controller public class AgencyController { @Autowired private AgencyService agencyService; @Autowired private AgencyMapper agencyMapper; @GetMapping(“/deleteAgencyPage/{id}”) […]

BaggageField updateValue method returns false in jUnit tests

Query asked by user EDIT: One problem was that Tracing.current() was null. I fixed this with the new @BeforeEach instead of the old @BeforeTestMethod: Tracer tracer; @BeforeEach void init() { tracer = Tracing.newBuilder().build().tracer(); TraceContext ctx = TraceContext.newBuilder().traceId(17).spanId(17).build(); Span span = tracer.toSpan(ctx); tracer.withSpanInScope(span); } Yet, updateValue still doesn’t work as there are no extras in the […]