Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a module to add Spring Native support #16498

Closed
1 task done
mraible opened this issue Sep 30, 2021 · 35 comments
Closed
1 task done

Create a module to add Spring Native support #16498

mraible opened this issue Sep 30, 2021 · 35 comments
Labels
area: feature request 💡 $$ bug-bounty $$ https://www.jhipster.tech/bug-bounties/ theme: blueprint 🐾 $500 https://www.jhipster.tech/bug-bounties/
Milestone

Comments

@mraible
Copy link
Contributor

mraible commented Sep 30, 2021

Overview of the feature request

Create a module to add Spring Native support to JHipster apps.

Motivation for or Use Case

Josh Long and I figured out the necessary steps this week and documented them in mraible/spring-native-examples. I also published an article about our experience on LinkedIn.

Related issues or PR

#13733

  • Checking this box is mandatory (this is just to show you read everything)
@mraible mraible added $$ bug-bounty $$ https://www.jhipster.tech/bug-bounties/ $500 https://www.jhipster.tech/bug-bounties/ labels Sep 30, 2021
@mshima
Copy link
Member

mshima commented Sep 30, 2021

I’m actually planning to add a modular generator.
Should be simple, but it’s a start.

I took a look at the steps. The modular generator will not help at the current state.

@github-actions
Copy link
Contributor

This issue is stale because it has been open 30 days with no activity.
Our core developers tend to be more verbose on denying. If there is no negative comment, possibly this feature will be accepted.
We are accepting PRs 😃.
Comment or this will be closed in 7 days

@mraible
Copy link
Contributor Author

mraible commented Oct 31, 2021 via email

@github-actions
Copy link
Contributor

github-actions bot commented Dec 1, 2021

This issue is stale because it has been open 30 days with no activity.
Our core developers tend to be more verbose on denying. If there is no negative comment, possibly this feature will be accepted.
We are accepting PRs 😃.
Comment or this will be closed in 7 days

@mraible
Copy link
Contributor Author

mraible commented Dec 1, 2021

I plan to start this next week. I was hoping we could upgrade to Spring Boot 2.6 first, but that might be difficult.

@sdeleuze
Copy link

sdeleuze commented Dec 1, 2021

Spring Native 0.11.0 should be released next week so good timing.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 1, 2022

This issue is stale because it has been open 30 days with no activity.
Our core developers tend to be more verbose on denying. If there is no negative comment, possibly this feature will be accepted.
We are accepting PRs 😃.
Comment or this will be closed in 7 days

@mraible
Copy link
Contributor Author

mraible commented Jan 1, 2022 via email

@ozkanpakdil
Copy link

Latest jhipster has SB 2.6.3 😃 watching this

@mraible
Copy link
Contributor Author

mraible commented Feb 4, 2022

@jhipster/developers Is our create a module guide up-to-date? I'd like to start creating this module today.

@mshima
Copy link
Member

mshima commented Feb 4, 2022

@mraible I would create a blueprint instead.
IMO we should drop module at v8, there is no advantage on implementing a module.
A blueprint acts as a module when using a custom command/generator.

@mraible
Copy link
Contributor Author

mraible commented Feb 4, 2022

@mshima If I create a blueprint, it'd likely only replace some values in needles. I suppose it might need to add files too.

Spring Boot 3 won't have a need for Spring Native because it'll be native by default. So that's something to consider - this likely won't be needed for JHipster 8 if it includes Spring Boot 3.

Another option would be to integrate Spring Native by default. Here's the current list of things you need to do to integrate it with JHipster v7.6. In my experience, integrating native does not cause any issues with JVM-mode. It's only activated when you run -Pnative.

Some of these issues might be bugs in Spring Native. spring-attic/spring-native#1378 (comment)

@mshima
Copy link
Member

mshima commented Feb 4, 2022

@mraible I can generate the initial blueprint if you want me to do it.

@mraible
Copy link
Contributor Author

mraible commented Feb 4, 2022

@mshima I'd love your help!

@mshima
Copy link
Member

mshima commented Feb 5, 2022

@mraible to regenerate your examples:

npm install -g mshima/generator-jhipster-native
jhipster-native --with-entities --skip-jhipster-dependencies

@mraible
Copy link
Contributor Author

mraible commented Feb 5, 2022

@mshima I tried it by running rm -rf in one of my example projects, then jhipster-native --with-entities. The result:

Changes to package.json were detected.

Running npm install for you to install the required dependencies.
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/generator-jhipster-native - Not found
npm ERR! 404
npm ERR! 404  '[email protected]' is not in this registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/mraible/.npm/_logs/2022-02-05T19_06_24_435Z-debug.log
ERROR! Command failed with exit code 1: npm install
Error: Command failed with exit code 1: npm install
    at makeError (/usr/local/lib/node_modules/generator-jhipster-native/node_modules/yeoman-environment/node_modules/execa/lib/error.js:60:11)
    at handlePromise (/usr/local/lib/node_modules/generator-jhipster-native/node_modules/yeoman-environment/node_modules/execa/index.js:118:26)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  shortMessage: 'Command failed with exit code 1: npm install',
  command: 'npm install',
  escapedCommand: 'npm install',
  exitCode: 1,
  signal: undefined,
  signalDescription: undefined,
  stdout: undefined,
  stderr: undefined,
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
}

Would a clone and npm link work better?

@mshima
Copy link
Member

mshima commented Feb 5, 2022

Need to use --skip-jhipster-dependencies flag. The blueprint is not released.

@mraible
Copy link
Contributor Author

mraible commented Feb 5, 2022

I got a bit further. This time, it succeeded in creating the project, but fails to run it.

 jhipster: Compilation failure: Compilation failure:
[ERROR] /Users/mraible/dev/spring-native-examples/spring-native-webflux/src/main/java/com/mycompany/myapp/web/rest/LogoutResource.java:[38,104] cannot find symbol
[ERROR]   symbol:   variable idToken
[ERROR]   location: class com.mycompany.myapp.web.rest.LogoutResource
[ERROR] /Users/mraible/dev/spring-native-examples/spring-native-webflux/src/main/java/com/mycompany/myapp/web/rest/LogoutResource.java:[43,21] variable idToken is already defined in method prepareLogoutUri(org.springframework.http.server.reactive.ServerHttpRequest,org.springframework.security.oauth2.client.registration.ClientRegistration,org.springframework.security.oauth2.core.oidc.OidcIdToken)
[ERROR] /Users/mraible/dev/spring-native-examples/spring-native-webflux/src/main/java/com/mycompany/myapp/web/rest/LogoutResource.java:[43,31] cannot find symbol
[ERROR]   symbol:   variable oidcUser
[ERROR]   location: class com.mycompany.myapp.web.rest.LogoutResource
[ERROR] -> [Help 1]

@mshima
Copy link
Member

mshima commented Feb 6, 2022

I got a bit further. This time, it succeeded in creating the project, but fails to run it.

 jhipster: Compilation failure: Compilation failure:
[ERROR] /Users/mraible/dev/spring-native-examples/spring-native-webflux/src/main/java/com/mycompany/myapp/web/rest/LogoutResource.java:[38,104] cannot find symbol
[ERROR]   symbol:   variable idToken
[ERROR]   location: class com.mycompany.myapp.web.rest.LogoutResource
[ERROR] /Users/mraible/dev/spring-native-examples/spring-native-webflux/src/main/java/com/mycompany/myapp/web/rest/LogoutResource.java:[43,21] variable idToken is already defined in method prepareLogoutUri(org.springframework.http.server.reactive.ServerHttpRequest,org.springframework.security.oauth2.client.registration.ClientRegistration,org.springframework.security.oauth2.core.oidc.OidcIdToken)
[ERROR] /Users/mraible/dev/spring-native-examples/spring-native-webflux/src/main/java/com/mycompany/myapp/web/rest/LogoutResource.java:[43,31] cannot find symbol
[ERROR]   symbol:   variable oidcUser
[ERROR]   location: class com.mycompany.myapp.web.rest.LogoutResource
[ERROR] -> [Help 1]

Reactive LogoutResource needed adjusts.
Reinstalling should fix it.

PS: I am not really trying to run the applications.
I am following the steps and matching the examples, and doing generator-jhipster blueprint support adjusts.
Will do that later this week or next.

@mraible
Copy link
Contributor Author

mraible commented Feb 6, 2022

Thanks for the fix @mshima! I tested all of the apps today:

  • spring-native-webflux - ✅
  • spring-native-mvc - ✅
  • angular-webflux - ✅
  • postgres-webflux - ✅
  • postgres-mvc - ✅

I'll create a PR with some minor improvements to the blueprint.

@mshima
Copy link
Member

mshima commented Feb 6, 2022

We probably should move the blueprint to jhipster org.

@mshima
Copy link
Member

mshima commented Feb 6, 2022

Or hipster-labs due to GitHub actions.
The build is not completing in 35min 😮 .

@mraible
Copy link
Contributor Author

mraible commented Feb 6, 2022

@mshima I figured out how to get R2DBC repositories to work! I had to add @Component to each Impl class and add SimpleR2dbcRepository as a type hint. See specifics in mraible/spring-native-examples#7.

I also noticed that the JHipster Native blueprint does not add Liquibase information to the postgres-webflux example, so we might need to adjust some install logic there. I also had to add a typeName for Liquibase + WebFlux:

typeNames = "com.zaxxer.hikari.util.ConcurrentBag$IConcurrentBagEntry[]"

@mraible
Copy link
Contributor Author

mraible commented Feb 7, 2022

@mshima I found another thing that needs to be added. If CacheConfiguration is activated, it fails to compile with the following error.

[ERROR] Failed to execute goal org.springframework.experimental:spring-aot-maven-plugin:0.11.2:generate (generate) on project flickr-2: Build failed during Spring AOT code generation: Unable to execute mojo: Compilation failure
[ERROR] /Users/mraible/dev/auth0-full-stack-java-example/target/generated-runtime-sources/spring-aot/src/main/java/org/springframework/cache/annotation/ContextBootstrapInitializer.java:[24,56] cannot find symbol
[ERROR]   symbol:   method setConfigurers(java.lang.Object)
[ERROR]   location: variable bean of type org.springframework.cache.jcache.config.ProxyJCacheConfiguration
[ERROR] -> [Help 1]

If I add @Profile("!native") to CacheConfiguration, my app compiles. However, when I try to run it after building it, I still get an error:

2022-02-06 22:04:13.178 ERROR 25028 --- [           main] org.hibernate.AssertionFailure           : HHH000099: an assertion failure occurred (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): java.lang.NullPointerException
2022-02-06 22:04:13.186 ERROR 25028 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory': Invocation of init method failed; nested exception is org.hibernate.AssertionFailure: Error calling ServiceLoader.Provider.type()
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[na:na]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[na:na]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[na:na]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[na:na]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[na:na]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[na:na]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[na:na]
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154) ~[na:na]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908) ~[na:na]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[na:na]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[na:na]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) ~[native-executable:2.6.3]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:414) ~[native-executable:2.6.3]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) ~[native-executable:2.6.3]
	at com.auth0.flickr2.Flickr2App.main(Flickr2App.java:80) ~[native-executable:na]
Caused by: org.hibernate.AssertionFailure: Error calling ServiceLoader.Provider.type()
	at org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader$ClassPathAndModulePathAggregatedServiceLoader.collectServiceIfNotDuplicate(AggregatedServiceLoader.java:272) ~[na:na]
	at org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader$ClassPathAndModulePathAggregatedServiceLoader.loadAll(AggregatedServiceLoader.java:201) ~[na:na]
	at org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader$ClassPathAndModulePathAggregatedServiceLoader.getAll(AggregatedServiceLoader.java:187) ~[na:na]
	at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.loadJavaServices(ClassLoaderServiceImpl.java:251) ~[na:na]
	at org.hibernate.boot.registry.selector.internal.StrategySelectorBuilder.buildSelector(StrategySelectorBuilder.java:105) ~[na:na]
	at org.hibernate.boot.registry.BootstrapServiceRegistryBuilder.build(BootstrapServiceRegistryBuilder.java:232) ~[na:na]
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.buildBootstrapServiceRegistry(EntityManagerFactoryBuilderImpl.java:479) ~[na:na]
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:222) ~[na:na]
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:182) ~[na:na]
	at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:52) ~[na:na]
	at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[na:na]
	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409) ~[na:na]
	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396) ~[na:na]
	at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[na:na]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[na:na]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[na:na]
	... 14 common frames omitted
Caused by: java.lang.NullPointerException: null
	at org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader$ClassPathAndModulePathAggregatedServiceLoader.collectServiceIfNotDuplicate(AggregatedServiceLoader.java:269) ~[na:na]
	... 29 common frames omitted

@mraible
Copy link
Contributor Author

mraible commented Feb 7, 2022

Upon further review, it seems that the profile annotation does not work and I have to comment out these annotations in CacheConfiguration.

@Configuration
@EnableCaching

This still results in the same error as above. I also tried to disable Hibernate's 2nd level cache in application.yml.

hibernate.cache.use_second_level_cache: false

That doesn't seem to help either. I'll continue investigating.

@mshima
Copy link
Member

mshima commented Feb 7, 2022

Added warnings for untested configurations.

@mraible
Copy link
Contributor Author

mraible commented Feb 7, 2022

Good idea. I had to remove caching for things to work. I added a workaround to my instructions. I believe this is because Spring Native doesn't support caching yet.

@mraible
Copy link
Contributor Author

mraible commented Feb 10, 2022

@mshima If you transfer your repo to @jdubois, he can transfer it to the JHipster org.

@mshima mshima closed this as completed Feb 10, 2022
@mshima mshima reopened this Feb 10, 2022
@mshima
Copy link
Member

mshima commented Feb 10, 2022

@mshima If you transfer your repo to @jdubois, he can transfer it to the JHipster org.

Done

@jdubois
Copy link
Member

jdubois commented Feb 11, 2022 via email

@mraible
Copy link
Contributor Author

mraible commented Feb 17, 2022

Just so folks know when reading this conversation, the blueprint is located at https://github.com/jhipster/generator-jhipster-native.

@DanielFran
Copy link
Member

@mraible @mshima Closing this issue since blueprint is now available ;)

@mraible
Copy link
Contributor Author

mraible commented May 13, 2022

Please grab the bug bounty for this one @mshima!

@mshima
Copy link
Member

mshima commented Jun 22, 2022

@DanielFran
Copy link
Member

@mshima: approved

@DanielFran DanielFran added this to the 7.9.0 milestone Jun 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: feature request 💡 $$ bug-bounty $$ https://www.jhipster.tech/bug-bounties/ theme: blueprint 🐾 $500 https://www.jhipster.tech/bug-bounties/
Projects
None yet
Development

No branches or pull requests

6 participants