Spring application shut down at startup - spring

I have this strange behaviour with my spring boot application where suddently the startup process doesn't work anymore. Here's the all the log:
I really can't say what's wrong since it stopped working. I also fetched on git the remote version of the code that is deployed and working right now. I use Intellij Idea as IDE, I have already restarted the IDE and the laptop.
I looked over the Internet but everyone having this issue has problems abot pom or dependency. I can't get a clue from the logs. Thanks in advance.
EDIT: Here is my pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>it.reag</groupId>
<artifactId>reag-common-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>reag-mailsender-batch</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>it.reag</groupId>
<artifactId>reag-common-api-model</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version>
</dependency>
</dependencies>
<build>
<finalName>MailSenderBatch</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Note that if I change the spring-boot-starter dependency with spring-boot-starter-web the app works, but I don't understand why. I don't use any of the feature of web environment. Also, it worked perfectly until the other day with the spring-boot-starter dependency.

Leaving this answer as it may help others. If one defines a parent in pom like you have here:
<parent>
<groupId>it.reag</groupId>
<artifactId>reag-common-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
Then a simple dependency of spring-boot-starter-web in this module pom may not be the same as you expected, it may be customized in parent, aka reag-common-api pom, servlet container may be removed there. This happens because of dependency hierachy rule in maven. In this way, in order to verify that a missing container is the reason why spring application starts and quits, one can use mvn dependency:tree to see if a tomcat or undertow or netty is shown as a container (not an exact expression).
In my project, this would be neede for submodule pom:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
As its parent has this:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>

Related

Unable to compile after adding dependency to POM.xml

I have an existing project and i need to add Spring Security and Spring Security Test.
I can't figure out how to add it with IntelliJ.
I know how to do this when creating a new project and I have the PlugIn installed.
Please help me find out how to add it to an existing project
When I add the dependencies manually to the POM.xml, I get the following error
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method defaultSecurityFilterChain in org.springframework.boot.autoconfigure.security.servlet.SpringBootWebSecurityConfiguration required a bean of type 'org.springframework.security.config.annotation.web.builders.HttpSecurity' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.security.config.annotation.web.builders.HttpSecurity' in your configuration.
Disconnected from the target VM, address: '127.0.0.1:59290', transport: 'socket'
Process finished with exit code 0
Here is my POM.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.exaple.pma</groupId>
<artifactId>projectmanagement</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>projectmanagement</name>
<description>projectmanagement</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
UPDATE - 1/18/2022
when I run
mvnw spring-boot:run
from Terminal on Windows, it works. When i click the DEBUG icon in IntelliJ, i get this exception. How do I fix this? Running from Terminal to debug once is fine but the point of using an IDE diminishes if I need to run the project from Terminal.
To add new dependency:
First visit https://mvnrepository.com/ and search the dependency you want to add. Then copy that dependency.
Now go to IntelliJ and open pom.xml and add your copied dependency here.

NoSuchMethodError: org.springframework.plugin.core.PluginRegistry.getPluginOrDefaultFor

Everything was fine, even with Swagger however suddenly after new build project won't compile throwing
Caused by: org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NoSuchMethodError: org.springframework.plugin.core.PluginRegistry.getPluginOrDefaultFor(Ljava/lang/Object;Lorg/springframework/plugin/core/Plugin;)Lorg/springframework/plugin/core/Plugin;
I have tried solution from this link:
https://github.com/springfox/springfox/issues/2932
however compilation error still persist.
I am attaching pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.geborskimateusz.microservices.composite.movie</groupId>
<artifactId>movie-composite-service</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>movie-composite-service</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<swagger.version>3.0.0-SNAPSHOT</swagger.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.geborskimateusz</groupId>
<artifactId>api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.geborskimateusz</groupId>
<artifactId>util</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-webflux</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-test-support</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>jcenter-snapshots</id>
<name>jcenter</name>
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Any ideas, is this related to swagger version?
This error happens when a piece of code has been compiled with a given method signature, but at runtime, another is found.
This usually happens when there's a difference between the version of a dependency used at compile time, and the dependency that is actually provided to the program at runtime.
We just had this error as well with a colleague, and we fixed it by simply changing the spring boot version to 2.2.2.
Not sure what exactly happened, but given the version is a SNAPSHOT, a wild guess would be that the last working version of springfox (working for you and us) was compiled with a Spring boot version inferior to 2.2.2.
That boot version had a different method signature for getPluginOrDefaultFor (or possibly the method didn't exist at all).
Your program sees no difference, because the swagger lib's API didn't change, so
it seems like nothing changed and there's suddenly an error.
But the actual swagger lib's underlying implementation relies on some method from Spring Boot 2.2.2, which it doesn't find in your setup since Boot's version is 2.1.0, and this generates a conflict between what it expects to find and what it actually does.
Anyway, just upgrading your Boot to 2.2.2 should fix it ; possibly downgrading spring-fox to 2.9.2 if you don't need the webflux module- but it seems you do (didn't get the chance to try, because in our case we do need the springfox webflux dependency)

How to verify a Spring feature/Bug fix is available in the Spring boot version which i am using?

I am working on a spring batch program to process data from sql and write to an xml. I used staxEventItemWriter to do that. But due to this issue https://jira.spring.io/browse/BATCH-1377 i am not able to fix the namespace issue. When we look at comments on this Jira card it says its fixed in 2010. But its not available in the latest spring boot versions which i am using. i tried with the patch class described in the Jira card its working fine for me.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.demo.sitemap</groupId>
<artifactId>SqlToXml</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>SqlToXml</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-oxm -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>3.0.6.RELEASE</version>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.10</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.4.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
How to verify a Spring feature/Bug fix is available in the Spring boot version which i am using?
You are using Spring Boot 2.0.4.RELEASE. This will bring Spring Batch version 4.0.1.RELEASE. You can find more details about dependencies using the Spring Boot Initializr REST API.
The issue BATCH-1377 is marked as resolved in version 2.1.0.RC1 and is also available in 4.0.1.RELEASE.
But its not available in the latest spring boot versions which i am using. i tried with the patch class described in the Jira card its working fine for me.
The patch suggested by the contributor uses an additional property rootTagNamePrefix but this was modified as per this comment to use the naming convention {uri}prefix:root in order to be consistent with Spring WS. The issue was fixed here: https://github.com/spring-projects/spring-batch/commit/f56ee747296961917caa38fa9e14785dafc0b18b
So in your case, you need to use this naming convention if you want to add a namespace to the root tag. See example here: https://github.com/spring-projects/spring-batch/blob/f56ee747296961917caa38fa9e14785dafc0b18b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemWriterTests.java#L287

Spring Boot: does #Entity Annotation exist?

I watched this Spring Boot tutorial: https://javabrains.io/courses/spring_bootquickstart/lessons/Creating-a-Spring-Data-JPA-Repository
and it puts an #Entity annotation before a class name. When I tried to do it in my code, I got an Error saying "can't resolve #Entity".
Here is my pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath/><!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Do you know what is the problem?
I also faced this problem recently. For me, the spring-boot-starter-data-jpa dependency was the issue. Although it was in the pom.xml file without any errors, but the jars were not there in classpath - even after syncing maven and importing dependencies multiple times in different ways ( mvn clean/update/install).
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
The IDE I was using was IntelliJ Idea.
What worked for me at last : I just put this dependency over all other dependencies inside the <dependencies> ... </dependencies> tag, i.e just changed the order of dependencies and synced. That worked in my case, not sure why.
Below is my pom.xml file contents for reference.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dev.sanskar.courses</groupId>
<artifactId>course-api</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api -->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator -->
<!-- https://mvnrepository.com/artifact/org.hibernate.javax.persistence/hibernate-jpa-2.1-api -->
<!-- https://mvnrepository.com/artifact/org.hibernate.javax.persistence/hibernate-jpa-2.1-api -->
<!-- https://mvnrepository.com/artifact/javax.persistence/persistence-api -->
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Use spring-boot-starter-data-jpa
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
It works for me ... :)
Do not use the following one
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
I added this dependency
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
</dependency>
Add this and enjoy.
Spring STS usually shows this error when the set up isn't correct.
Go to the line containing the error
Click on the alert bulb so that it can suggest possible fixes
From the options, choose the "Fix project setup"
Follow the rest so that the project then re-aligns the import order.
suppose you have missed a dependency.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
There are useful sample spring boot projects in this github page.it will be helpful to have a look.
I had the same problem. After I configured the new dependency on pom.xml file, the #Entity annotation is not found because these dependencies is not found. To solve it, the IntelliJ IDE then suggested me to load the Maven changes. On the pom.xml screen, click on the icon to reload Maven.
Make sure you Maven projects are imported successfully.
In the lower right corner of your IntelliJ there will a prompt asking you if you want to import the changes. It will also ask you if you want to enable Auto-Import.
In my case, by adding the spring-boot-starter-data-jpa dependency to the classpath it worked.
Do a force update mvn clean install -U or you can right click on your project -->maven--> update if you are using eclipse/STS. this synchronizes the IDE with pom dependencies.
Seems you are working with EclipseLink JPA implementation,
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.1.0</version>
<scope>compile</scope>
</dependency>
Spring Data JPA works with Hibernate implementation by default. We need to exclude unnecessary Hibernate dependencies from spring-boot-starter-data-jpawhen working with other JPA implementations.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</exclusion>
</exclusions>
</dependency>
If you are working with Hibernate, just spring-boot-starter-data-jpa is enough in your case.
I also seen "can't resolve #Entity" issue because of my IDE. In eclipse, click Project option -> Clean the project. This is solved my issue when project dependencies out of sync with IDE.
Click on the red bulb next to the #Entity annotation.
Choose "Add dependency" - choose "javax.persistence.api" (NOT jakarta)
Most of the answers here are hit and try types which doesn't explain why #Entity annotation was not working and why it started working after adding certain dependencies.
Here's how it works-
For using persistence annotations you need to add relevant dependencies with their version, let's say we add spring-boot-starter-data-jpa as follows-
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.6.6</version>
</dependency>
Now when you are using Intellij Idea as your IDE, you need to reload your maven project to re read the dependencies from your pom.xml.
Once you do that, #Entity annotation would be available for use.
go to File -> Project Structure -> Project Settings -> Facets in Intellij Idea
click "+" and add "JPA" module
i faced same issue, after add this dependencies fixed my issue
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
</dependency>
What Worked For Me In Last:-
Go To File -> Project Structure -> Modules -> Click On Your Project Name
Then Go To Dependencies click "+" and Then -> Library -> From Maven
Then Search For javax.persistence.api Then Click Ok And Apply Changes
I had the same issues recently and i resolved it using adding this dependency that given below. I think the version change in spring boot made this error, now javax.persistence is not available instead we can use jakarta.persistence
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.1.6.Final</version>
<type>pom</type>
</dependency>
put this in your file at the top as an import statement
import javax.persistence.*;

Spring Boot unable to find jsp files on ElasticBeanstalk AWS

It works good when the application is running from Eclipse. But the problem is starting after i packaging the app to JAR or WAR and running it.
Getting 404 on every pages.
Here what i have done so far:
Here my POM file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>springtry</groupId>
<artifactId>spring</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>spring Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-solr</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<!-- JSTL for JSP -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<scope>provided</scope>
</dependency>
<!-- Need this to compile JSP -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- Need this to compile JSP, tomcat-embed-jasper version is not working,
no idea why -->
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>4.6.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.10</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
So to resolve the issue i have changed my elastic beanstalk from Java to Tomcat. And now it works with WAR.
Using the Java i was not able to run the webapp
For jar packaging, the jsp files should be in src/main/resources/META-INF/resources/.
For war packaging src/main/webapp/ is good.
Also, I guess with war packaging, you are probably not implementing SpringBootServletInitializer with it's method configure(...) in your config main class.
A complete example is here

Resources