Skip to content

Instantly share code, notes, and snippets.

@amirmv2006
Created June 20, 2021 07:58
Show Gist options
  • Save amirmv2006/e9eb826d3037354be379b62f0f75dfa8 to your computer and use it in GitHub Desktop.
Save amirmv2006/e9eb826d3037354be379b62f0f75dfa8 to your computer and use it in GitHub Desktop.
Spring Native Hints for Firestore Repositories
package ir.amv.enterprise.locorepo.common.gcp.adapter;
import com.google.cloud.spring.autoconfigure.firestore.FirestoreRepositoriesAutoConfiguration;
import com.google.cloud.spring.data.firestore.SimpleFirestoreReactiveRepository;
import com.google.cloud.spring.data.firestore.repository.support.FirestoreRepositoryFactoryBean;
import org.springframework.nativex.hint.AccessBits;
import org.springframework.nativex.hint.JdkProxyHint;
import org.springframework.nativex.hint.NativeHint;
import org.springframework.nativex.hint.TypeHint;
import org.springframework.nativex.type.NativeConfiguration;
@NativeHint(trigger = FirestoreRepositoriesAutoConfiguration.class,
types = @TypeHint(types = {
FirestoreRepositoryFactoryBean.class,
SimpleFirestoreReactiveRepository.class
}, typeNames = {
"com.google.cloud.spring.data.firestore.mapping.FirestoreMappingContext"
}, access = AccessBits.CLASS | AccessBits.DECLARED_METHODS | AccessBits.DECLARED_CONSTRUCTORS
| AccessBits.RESOURCE)
,
jdkProxies = @JdkProxyHint(typeNames = {
"com.google.cloud.spring.data.firestore.FirestoreReactiveRepository",
"org.springframework.aop.SpringProxy",
"org.springframework.aop.framework.Advised",
"org.springframework.core.DecoratingProxy"
})
)
public class FirestoreRepositoriesHints implements NativeConfiguration {
}
@amirmv2006
Copy link
Author

this class will be detected using SPI meaning the FQN name of the class should be put into a file named org.springframework.nativex.type.NativeConfiguration in resources/META-INF/services.
The module containing this code should be on the classpath of spring aot build. for example, when using maven:

<plugin>
  <groupId>org.springframework.experimental</groupId>
  <artifactId>spring-aot-maven-plugin</artifactId>
  <version>${spring-native.version}</version>
  <dependencies>
    <dependency>
      <groupId>ir.amv.enterprise.laas.webapp.libs</groupId>
      <artifactId>gcp-adapter</artifactId>
      <version>${project.version}</version>
    </dependency>
  </dependencies>
  <executions>...</executions>
</plugin>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment