GoogleCloudPlatform / spring-cloud-gcp

New home for Spring Cloud GCP development starting with version 2.0.
Apache License 2.0
423 stars 315 forks source link

Datastore: spring-native support #1279

Open dosomder opened 2 years ago

dosomder commented 2 years ago

Is there any support for spring-native when using datastore and its DatastoreRepository?

I have declared my repository like this:

public interface CategoryRepository extends DatastoreRepository<Category, Long> {
}

Then I have another class that uses the repo:

@Component
public class Gateway {
  @Autowired
  private CategoryRepository categoryRepository;
  ......
}

While the project builds using spring-native, on start up I get the following exception:

***************************
APPLICATION FAILED TO START
***************************

Description:

Field categoryRepository in ch.do.storage.repo.Gateway required a bean of type 'ch.do.storage.repo.CategoryRepository' that could not be found.

The injection point has the following annotations:
        - @org.springframework.beans.factory.annotation.Autowired(required=true)

Action:

Consider defining a bean of type 'ch.do.storage.repo.CategoryRepository' in your configuration.

In the file build/generated/resources/aotMain/MAIN-INF/spring.components, there is the following entry:

ch.do.storage.repo.CategoryRepository=org.springframework.data.repository.Repository

Is there some kind of additional configuration needed (like NativeHint)? How would it look like?

JoeWang1127 commented 2 years ago

Hi @dosomder, sorry but we don't support spring-native way using datastore.

elefeint commented 2 years ago

You can try to add spring native dependency, which would likely take care of Spring-specific annotations/reflection. But we have not tested these projects with native at this point.

dosomder commented 2 years ago

Hi @elefeint

I am using spring-native and the supported spring-boot version, still the exception from the first post appears

elefeint commented 2 years ago

Thanks for confirming! We have plans to look into native compilation compatibility after Spring Boot 3.0 comes out, but it definitely won't be supported until 2023.

dosomder commented 2 years ago

Cool, looking forward to it because the start up time at the moment is really bad