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

Generated application won't start with springBootVersion-3.1.3; throws java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication #23327

Closed
anothergoodguy opened this issue Aug 28, 2023 · 13 comments

Comments

@anothergoodguy
Copy link

Overview of the issue

Hi
I have used the attached .yo.rc.json to generate a sample app to validate 3.1.3 introduction. after building the application with ./gradlew clean -Pdev bootJar the application wont start with java -jar build/libs/sample-rest-0.0.1-SNAPSHOT.jar
Here is the error I get:

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:95)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
	at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
	at com.sample.platform.SampleRestApp.main(SampleRestApp.java:68)
	... 8 more
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:592)
	at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:149)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
	... 9 more ```


##### **Motivation for or Use Case**

Application won't start

##### **Reproduce the error**

basic generation flow and used the attached jdl for sample entities

##### **Related issues**

not aware of any

##### **Suggest a Fix**

Will add as comments if i find any...

##### **JHipster Version(s)**

latest commits of the  branch `main` and commit  `6db9e9e8`.
I suspect, this is something to do with Spring-boot-`3.1.3`, if I change the version to `3.1.2` it works fine...


##### **JHipster configuration**
jhipster info
WARNING! Since JHipster v8, the jhipster command will not use the locally installed generator-jhipster.
    If you want to execute the locally installed generator-jhipster, run: npx jhipster

        ██╗ ██╗   ██╗ ████████╗ ███████╗   ██████╗ ████████╗ ████████╗ ███████╗
        ██║ ██║   ██║ ╚══██╔══╝ ██╔═══██╗ ██╔════╝ ╚══██╔══╝ ██╔═════╝ ██╔═══██╗
        ██║ ████████║    ██║    ███████╔╝ ╚█████╗     ██║    ██████╗   ███████╔╝
  ██╗   ██║ ██╔═══██║    ██║    ██╔════╝   ╚═══██╗    ██║    ██╔═══╝   ██╔══██║
  ╚██████╔╝ ██║   ██║ ████████╗ ██║       ██████╔╝    ██║    ████████╗ ██║  ╚██╗
   ╚═════╝  ╚═╝   ╚═╝ ╚═══════╝ ╚═╝       ╚═════╝     ╚═╝    ╚═══════╝ ╚═╝   ╚═╝
                            https://www.jhipster.tech
Welcome to JHipster v8.0.0-beta.2

Welcome to the JHipster Information Sub-Generator


[email protected] /home/jhipster/app/biskate/tm-trial
└── [email protected]



##### **JHipster configuration, a `.yo-rc.json` file generated in the root folder**


<details>
<summary>.yo-rc.json file</summary>
<pre>
{
  "applicationType": "monolith",
  "authenticationType": "oauth2",
  "baseName": "sampleRest",
  "blueprints": [],
  "buildTool": "gradle",
  "cacheProvider": "infinispan",
  "clientFramework": "react",
  "clientTheme": "none",
  "creationTimestamp": 1692556734396,
  "cypressAudit": true,
  "cypressCoverage": null,
  "databaseType": "sql",
  "devDatabaseType": "mysql",
  "devServerPort": 9060,
  "dtoSuffix": "DTO",
  "enableGradleEnterprise": null,
  "enableHibernateCache": true,
  "enableSwaggerCodegen": false,
  "enableTranslation": true,
  "entities": [
    "WishList",
    "Address",
    "Category",
    "Customer",
    "Product"
  ],
  "entitySuffix": "",
  "gradleEnterpriseHost": null,
  "jhiPrefix": "tm",
  "jhipsterVersion": "8.0.0-beta.2",
  "languages": [
    "en"
  ],
  "lastLiquibaseTimestamp": 1693197946000,
  "messageBroker": false,
  "microfrontend": false,
  "microfrontends": [],
  "nativeLanguage": "en",
  "otherModules": [],
  "packageFolder": "com/sample/platform",
  "packageName": "com.sample.platform",
  "pages": [],
  "pkType": "UUID",
  "prodDatabaseType": "mysql",
  "reactive": false,
  "searchEngine": "elasticsearch",
  "serverPort": null,
  "serverSideOptions": [
    "searchEngine:elasticsearch"
  ],
  "serviceDiscoveryType": false,
  "skipCheckLengthOfIdentifier": false,
  "skipClient": false,
  "skipFakeData": false,
  "skipUserManagement": true,
  "testFrameworks": [
    "cypress",
    "gatling",
    "cucumber"
  ],
  "websocket": false,
  "withAdminUi": true
}
</pre>
</details>


##### **Environment and Tools**

openjdk version "17.0.8" 2023-07-18
OpenJDK Runtime Environment Temurin-17.0.8+7 (build 17.0.8+7)
OpenJDK 64-Bit Server VM Temurin-17.0.8+7 (build 17.0.8+7, mixed mode, sharing)

git version 2.25.1

node: v18.17.1
npm: 9.6.7

'docker' command could not be found

##### **JDL for the Entity configuration(s) `entityName.json` files generated in the `.jhipster` directory**

<details>
<summary>JDL entity definitions</summary>

<pre>
entity WishList {
  title String required
  restricted Boolean
}
entity Address {
  address1 String
  address2 String
  city String
  postcode String required maxlength(10)
  country String required maxlength(2)
}
entity Category {
  description String required
  sortOrder Integer
  dateAdded LocalDate
  dateModified LocalDate
  status CategoryStatus
}
entity Customer {
  firstName String
  lastName String
  email String
  telephone String
}
entity Product {
  title String required
  keywords String
  description String
  rating Integer
  dateAdded LocalDate
  dateModified LocalDate
}
enum CategoryStatus {
  AVAILABLE,
  RESTRICTED,
  DISABLED
}

relationship OneToMany {
  WishList{product(title)} to Product{wishList}
  Customer{wishList(title)} to WishList{customer}
  Customer{address} to Address{customer}
}
relationship ManyToOne {
  Category{parent} to Category
}
relationship ManyToMany {
  Category{product(title)} to Product{category}
}

dto WishList, Address, Category, Customer, Product with mapstruct
paginate WishList, Address, Category, Customer, Product with infinite-scroll
service WishList, Address, Category, Customer, Product with serviceClass
search WishList, Address, Category, Customer, Product with elasticsearch
filter WishList, Address, Category, Customer, Product

</pre>
</details>


Congratulations, JHipster execution is complete!
If you find JHipster useful consider sponsoring the project https://www.jhipster.tech/sponsors/

Thanks for using JHipster!

[.yo-rc.json](https://github.com/jhipster/generator-jhipster/files/12450442/yo-rc.json.txt)
<!--
To provide all information we need, you should run `jhipster info` in the project root folder, and
copy/paste the result here.
The `.yo-rc.json` file generated in the root folder is mandatory for bug reports. This will help us to replicate the scenario.
You should remove any sensitive information like the rememberMe key or the jwtSecretKey key.
---
If you have a JDL please wrap it in below structure
  <details>
  <summary>JDL definitions</summary>
  <pre>
     JDL content here
  </pre>
  </details>
-->

##### **Entity configuration(s) `entityName.json` files generated in the `.jhipster` directory**

N/A

##### **Browsers and Operating System**

MACOS - Ventura - 13.4.1 
JDK - openjdk version "17.0.8.1" 2023-08-24

- [X] Checking this box is mandatory (this is just to show you read everything)

<!-- Love JHipster? Please consider supporting our collective:
👉  https://opencollective.com/generator-jhipster/donate -->
@github-actions
Copy link
Contributor

github-actions bot commented Aug 28, 2023

JHipster has completed the sample check
.yo-rc.json: valid
Entities JDL: valid
Application: successfully generated
Frontend check: success
Backend check: success
E2E check: success

@qmonmert
Copy link
Contributor

@anothergoodguy I think you must use prod profile: ./gradlew clean -Pprod bootJar

@anothergoodguy
Copy link
Author

@qmonmert we have dev, stage and prod environments. I usually duplicate dev for stage and make the needed env changes. thanks for the quick resolution. will try to test later tonight and will share you the observations, if any.

@anothergoodguy
Copy link
Author

here are some observations:

  1. build with ./gradlew clean -Pprod bootJar
  2. run with java -jar build/libs/sample-rest-0.0.1-SNAPSHOT.jar
  3. observe that it's using Spring Boot 3.1.2 instead of 3.1.3, even though the gradle properties has the correct entry
# Dependency versions
jhipsterDependenciesVersion=8.0.0-SNAPSHOT
# The spring-boot version should match the one managed by
# https://mvnrepository.com/artifact/tech.jhipster/jhipster-dependencies/8.0.0-SNAPSHOT
springBootVersion=3.1.3
# The hibernate version should match the one managed by
# https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-dependencies/3.1.3 -->
hibernateVersion=6.2.7.Final
mapstructVersion=1.5.5.Final
archunitJunit5Version=1.1.0

and the result:

java -jar build/libs/sample-rest-0.0.1-SNAPSHOT.jar

        ██╗ ██╗   ██╗ ████████╗ ███████╗   ██████╗ ████████╗ ████████╗ ███████╗
        ██║ ██║   ██║ ╚══██╔══╝ ██╔═══██╗ ██╔════╝ ╚══██╔══╝ ██╔═════╝ ██╔═══██╗
        ██║ ████████║    ██║    ███████╔╝ ╚█████╗     ██║    ██████╗   ███████╔╝
  ██╗   ██║ ██╔═══██║    ██║    ██╔════╝   ╚═══██╗    ██║    ██╔═══╝   ██╔══██║
  ╚██████╔╝ ██║   ██║ ████████╗ ██║       ██████╔╝    ██║    ████████╗ ██║  ╚██╗
   ╚═════╝  ╚═╝   ╚═╝ ╚═══════╝ ╚═╝       ╚═════╝     ╚═╝    ╚═══════╝ ╚═╝   ╚═╝

:: JHipster 🤓  :: Running Spring Boot 3.1.2 :: Startup profile(s) prod ::
:: https://www.jhipster.tech ::

@DanielFran
Copy link
Member

DanielFran commented Aug 29, 2023

@anothergoodguy Did you build locally jhipster bom and generator projects?

@anothergoodguy
Copy link
Author

anothergoodguy commented Aug 29, 2023

no @DanielFran I dont have the bom project locally, I have generator locally and am using the generator by building the docker image locally.

@DanielFran
Copy link
Member

@anothergoodguy Can you confirm this is still happening?
@qmonmert confirmed that with current main branch this does not happen now...

@qmonmert
Copy link
Contributor

qmonmert commented Sep 1, 2023

@DanielFran I confirm, but this is strange

@anothergoodguy
Copy link
Author

hey @DanielFran,
I have the commit 15970f6164. and this is still happening with gradle, but I tried out of curiosity with maven as well, interestingly it's working fine with maven. See the results below:

Gradle outout:

java -jar build/libs/store-0.0.1-SNAPSHOT.jar
Exception in thread "main" java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:95)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
	at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
	at com.sample.platform.StoreApp.main(StoreApp.java:68)
	... 8 more
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:592)
	at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:149)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
	... 9 more

Maven output:

java -jar target/store-0.0.1-SNAPSHOT.jar

        ██╗ ██╗   ██╗ ████████╗ ███████╗   ██████╗ ████████╗ ████████╗ ███████╗
        ██║ ██║   ██║ ╚══██╔══╝ ██╔═══██╗ ██╔════╝ ╚══██╔══╝ ██╔═════╝ ██╔═══██╗
        ██║ ████████║    ██║    ███████╔╝ ╚█████╗     ██║    ██████╗   ███████╔╝
  ██╗   ██║ ██╔═══██║    ██║    ██╔════╝   ╚═══██╗    ██║    ██╔═══╝   ██╔══██║
  ╚██████╔╝ ██║   ██║ ████████╗ ██║       ██████╔╝    ██║    ████████╗ ██║  ╚██╗
   ╚═════╝  ╚═╝   ╚═╝ ╚═══════╝ ╚═╝       ╚═════╝     ╚═╝    ╚═══════╝ ╚═╝   ╚═╝

:: JHipster 🤓  :: Running Spring Boot 3.1.3 :: Startup profile(s) dev ::
:: https://www.jhipster.tech ::

@anothergoodguy
Copy link
Author

opps looks like I overlooked that the app didn't start in maven either but looks like a different issue, sharing it here thinking these might be classpath corrections:

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2023-09-01T22:27:50.714+05:30 ERROR 11977 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   :

***************************
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:

    co.elastic.clients.transport.endpoints.SimpleEndpoint.pathEncode(SimpleEndpoint.java:99)

The following method did not exist:

    'java.lang.String org.apache.http.client.utils.URLEncodedUtils.formatSegments(java.lang.String[])'

The calling method's class, co.elastic.clients.transport.endpoints.SimpleEndpoint, was loaded from the following location:

    jar:file:/Users/thatguy/jhipster/biskate/store-trial/target/store-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/elasticsearch-java-8.7.1.jar!/co/elastic/clients/transport/endpoints/SimpleEndpoint.class

The called method's class, org.apache.http.client.utils.URLEncodedUtils, is available from the following locations:

    jar:file:/Users/thatguy/jhipster/biskate/store-trial/target/store-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/httpclient-4.5.3.jar!/org/apache/http/client/utils/URLEncodedUtils.class

The called method's class hierarchy was loaded from the following locations:

    org.apache.http.client.utils.URLEncodedUtils: jar:file:/Users/thatguy/jhipster/biskate/store-trial/target/store-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/httpclient-4.5.3.jar!/


Action:

Correct the classpath of your application so that it contains compatible versions of the classes co.elastic.clients.transport.endpoints.SimpleEndpoint and org.apache.http.client.utils.URLEncodedUtils

@mshima
Copy link
Member

mshima commented Sep 2, 2023

Both errors are related to version conflicts. Which may be fixed (or caused) by transitive dependencies.
jhipster main is a moving target, so is jhipster-bom main.
It’s not possible to use a jhipster git commit without the matching jhipster-bom commit.

If it’s not reproducible in main using a current jhipster-bom snapshot we should close the issue.

@anothergoodguy
Copy link
Author

I tested it on a setup with both bom and geneator latest commits and this issue is no longer present with gradle; but I see the above mentioned classpath issue in maven still. you may take a call to close the ticket as per the program guidelines.
However there is some other classpath/aceess-restrictions issue I see on both main branch and 8.0.0-beta.2; and I will file a separate issue ticket for it.

@mshima
Copy link
Member

mshima commented Sep 5, 2023

@anothergoodguy the original issue is not reproducible anymore.
If you the elasticseach bug persists please open a new issue.

@mshima mshima closed this as completed Sep 5, 2023
@deepu105 deepu105 added this to the 8.0.0-rc.1 milestone Oct 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants