I’ve migrated my application to Vaadin 25.
The application uses Spring Data MongoDB, but repository access is no longer working. The same code worked correctly with Vaadin 24 and Spring Boot 3.8.
Now, if I call findByName(String name), I get a null return.
At the moment, the only approach that works is accessing MongoDB directly via MongoClient:
MongoClient mongoClient = MongoClients.create();
MongoDatabase database = mongoClient.getDatabase(“mydb”);
MongoCollection myColl = database.getCollection(“MyCollection”);
With this approach, I then have to manually map bson.Document instances to my domain object (MyObject).
Am I missing some configuration or change required for Vaadin 25 / Spring Boot 4? Any help would be appreciated.
Nicola
Application configuration
Application.java
@SpringBootApplication
@StyleSheet(Lumo.STYLESHEET)
@StyleSheet(“styles.css”)
@EnableMongoRepositories
public class Application implements AppShellConfigurator {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Security configuration
SecurityConfiguration.java
@Configuration
@EnableWebSecurity
public class SecurityConfiguration {
@Bean
SecurityFilterChain eventFilterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(auth ->
auth.requestMatchers("/public/**").permitAll()
);
http.with(VaadinSecurityConfigurer.vaadin(), configurer ->
configurer.loginView(LoginView.class)
);
return http.build();
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
Repository
MyCollectionRepo.java
public interface MyCollectionRepo extends
MongoRepository<MyObject, String>,
PagingAndSortingRepository<MyObject, String> {
MyObject findByName(String name);
MyObject getById(String id);
}
Service layer
MyCollectionService.java
@Repository
public class MyCollectionService {
private final MyCollectionRepo myR;
private final MongoTemplate db;
@Autowired
public MyCollectionService(MyCollectionRepo myRepo, MongoTemplate mongoTemplate) {
this.myR = myRepo;
this.db = mongoTemplate;
}
public List<MyObject> findAll() {
return myR.findAll();
}
public MyObject getById(String id) {
return myR.getById(id);
}
public MyObject findByName(String name) {
return myR.findByName(name);
}
}