Spring initialization for the first time [closed] - java

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 9 days ago.
Improve this question
I'm new to spring and I'm practicing but I don't understand this error in console.
2023-02-11T08:19:34.154-03:00 INFO 4048 --- [ main] com.sacavix.todoapp.TodoAppApplication : Starting TodoAppApplication using Java 19.0.1 with PID 4048 (C:\Users\matia\GitHub\ToDo API\target\classes started by matia in C:\Users\matia\GitHub\ToDo API) 2023-02-11T08:19:34.159-03:00 INFO 4048 --- [ main] com.sacavix.todoapp.TodoAppApplication : No active profile set, falling back to 1 default profile: "default" 2023-02-11T08:19:34.788-03:00 INFO 4048 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode. 2023-02-11T08:19:34.808-03:00 INFO 4048 --- [ main]
looks like this:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.2</version>
<relativePath/>
</parent>
<groupId>com.sacavix</groupId>
<artifactId>todoapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>TodoApp</name>
<description>Demo project for Spring Boot</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-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</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>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
</dependencies>
I tried to run the program and I get that error, it was to see if the program was working correctly and to see Swagger in action.
I need help to be able to solve the problem. I know it may be due to compatibility errors, but I don't know how to fix it.

Probably version of Spring boot and version of swagger does not match. Instead of Swagger dependencies you can use
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.12</version>
</dependency>
My spring boot version is 2.6.4
You need configuration like this, no need EnableSwagger.

Related

Spring boot application shutdown immediatly after adding jpa and mysql dependencies

I added jpa and mysql dependences. Now my spring boot application it shutdown immediate after starting.
The console log:
:: Spring Boot :: (v3.0.0)
2022-12-02T01:02:59.232+03:00 INFO 13164 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-12-02T01:03:01.977+03:00 ERROR 13164 --- [ restartedMain] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
pom.xml dependencies
<dependencies>
<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.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
SpringBootApplication.java
package com.example.tickets;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class TicketsApplication {
public static void main(String[] args) {
SpringApplication.run(TicketsApplication.class, args);
}
}
application.properties
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/theatres?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Europe/Kiev
spring.datasource.username=mysql
spring.datasource.password=mysql
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#spring.jpa.show-sql: true
I have already searched for the error in StackOverflow. There are some questions about it but none of them are working for me. I didnt found decision for my problem

How to resolve "Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured"

I am trying implement open-fiegn call from currrencyexchange module to currencyconversion but i am stuck at this error. Can anyone please help me with this. I have checked other answer and tried to add #spring.datasource.driver-class-name=com.mysql.jdbc.Driver but didn't work.
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-09-22 21:07:32.787 ERROR [currency-conversion-service,,] 261173 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (the profiles dev are currently active).
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.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.hashedin</groupId>
<artifactId>currency-conversion-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>currency-conversion-service</name>
<description>Currency Exchange Service template for HU SDE 22.3.2 Advanced Java track</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>2021.0.1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-openfeign -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>3.1.4</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.11</version>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>0.2.1</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.6.1</version>
</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>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.7.3</version>
</plugin>
</plugins>
</build>
</project>
application-properties
spring.application.name=currency-conversion-service
#spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.profiles.active=dev
server.port=8081
spring.cloud.config.enabled=false
eureka.client.serviceUrl.defaultZone=https://hu-22-java-adv-mastereureka-server-urtjok3rza-wl.a.run.app/eureka
eureka.instance.prefer-ip-address=true
eureka.instance.hostname=https://hu-22-java-adv-mastereureka-server-urtjok3rza-wl.a.run.app
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
If you want to use mysql you have to add mysql driver:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
The spring-boot-starter-data-jpa artifact can integrate with H2 embedded database. Add the following dependencies to your POM.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
then, add two script files into the src/main/resources folder:
schema.sql for creating the database
data.sql for populating the database
Note that with spring data JPA you get a default configuration for embedded database. You do not need to add database configuration to the application.properties file.
Add this version of derby in pom.xml:
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.11.1.1</version>
<scope>runtime</scope>
</dependency>
After making changes in pom.xml, force update the maven project
And add the following in applications.properties file:
#JPA
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database=default
spring.jpa.show-sql=true
#DATASOURCE
spring.datasource.continue-on-error=false
spring.datasource.generate-unique-name=false
spring.datasource.username=app
Maybe problem with the earlier default derby jar dependency
It worked after making the above changes

Spring Boot Application immediately shuts down after starting in external TOMCAT

Spring boot immediately shuts down after starting in external TOMCAT. But in Eclipse this runs well and JAR with embed too.
I use Tomcat 7 and JAVA 8.
I read a lot of webs and documentation which do not exist.
My Eclipse POM is:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>com.suez.demo</groupId>
<artifactId>Myapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Myappname</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<start-class>com.suez.demo.SuezApplication</start-class>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</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.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.notnoop.apns</groupId>
<artifactId>apns</artifactId>
<version>1.0.0.Beta6</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.7.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.0.RELEASE</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<generatePackage>com.suez.demo.ws</generatePackage>
<generateDirectory>${project.basedir}/src/main/java</generateDirectory>
<schemaDirectory>${project.basedir}/src/main/resources</schemaDirectory>
<schemaIncludes>
<include>*.wsdl</include>
</schemaIncludes>
</configuration>
</plugin>
</plugins>
</build>
Tomcat output log last lines are:
2018-06-29 10:27:37.874 INFO 640 --- [ost-startStop-3] com.suez.demo.SuezApplication : Started SuezApplication in 29.104 seconds (JVM running for 91.714)
2018-06-29 10:27:37.905 INFO 640 --- [ost-startStop-3] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#75e8c829: startup date [Fri Jun 29 10:27:11 CEST 2018]; root of context hierarchy
2018-06-29 10:27:37.936 INFO 640 --- [ost-startStop-3] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2018-06-29 10:27:37.952 INFO 640 --- [ost-startStop-3] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
Can someone help me please?
It's hard to say out of the information you've provided, but what looks suspicious to me is that you're using spring-boot-starter-web which in turn brings tomcat starter transitively.
I see that the packaging of this module is WAR, so its intended to run in an external web container, but on the other hand, you say that it runs fine in "JAR with embed too".
So it's a little bit confusing.
I've never by myself deployed spring boot application as a WAR file, but I believe you can go to Start.spring.io and generate a sample application that will package itself into WAR. This option is not shown by default, so you'll have to click on "switch to the full version" link

Spring Boot maven project from Eclipse doesn't work in Intellij

I have working spring boot maven project created in eclipse. Then i import its to Intellij Ultimate, everything goes fine, click run and:
and after this i have errors:
2017-02-15 12:46:58.459 ERROR 6020 --- [ restartedMain] o.s.boot.SpringApplication : Application startup failed
java.lang.IllegalStateException: Could not evaluate condition on org.springframework.boot.devtools.autoconfigure.DevToolsDataSourceAutoConfiguration due to javax/servlet/Filter not found. Make sure your own configuration does not rely on that class. This can also happen if you are #ComponentScanning a springframework package (e.g. if you put a #ComponentScan in the default package by mistake)
....
2017-02-15 12:46:58.478 ERROR 6020 --- [ restartedMain] o.s.b.f.s.DefaultListableBeanFactory : Destroy method on bean with name 'org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory' threw an exception
java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.context.annotation.AnnotationConfigApplicationContext#2f6c79e1: startup date [Wed Feb 15 12:46:56 CET 2017]; root of context hierarchy
Where is the problem ?
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 `http://maven.apache.org/xsd/maven-4.0.0.xsd">`
<modelVersion>4.0.0</modelVersion>
<groupId>com.twistezo</groupId>
<artifactId>StickyNotes</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>StickyNotes</name>
<description>StickyNotes SpringBoot app</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.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-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</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-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Starter class
#SpringBootApplication
public class StickyNotesApplication {
public static void main(String[] args) {
SpringApplication.run(StickyNotesApplication.class, args);
}
}
There is a known issue with IntelliJ IDEA Maven support and provided dependencies.
A workaround for your problem would be to change spring-boot-starter-tomcat dependency scope from provided to compile.
See also a related discussion for a similar case, but with a different dependency.

IntelliJ Process finished with exit code 0 when spring-boot run

I have a problem when starting spring-boot appication from IntelliJ-Idea. I don't have this problem when running application through terminal.
:: Spring Boot :: (v1.2.1.RELEASE)
2015-09-24 12:22:44.274 WARN 22380 --- [ main] n.sf.ehcache.config.CacheConfiguration : Cache 'publicationsCount' is set to eternal but also has TTI/TTL set. To avoid this warning, clean up the config removing conflicting values of eternal, TTI and TTL. Effective configuration for Cache 'publicationsCount' will be eternal='true', timeToIdleSeconds='0', timeToLiveSeconds='0'.
Process finished with exit code 0
I think this warn is not causing it. What may be the reason?
Deleting provided scope of spring-boot-starter-tomcat dependency helps me.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
I create a simple project from https://start.spring.io/ (sprint initializr) and added a simple controller to run the application.
#RestController
public class testController {
#GetMapping(value="/")
//#RequestMapping(value="/",method=RequestMethod.GET)
public String hello(){
return "Hello World!!";
}
}
but it wasn't getting started because my pom wasn't having
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
After adding this my application started...
2019-11-05 14:33:32.302 INFO 39079 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#dd20ebc, org.springframework.security.web.context.SecurityContextPersistenceFilter#57b1ec84, org.springframework.security.web.header.HeaderWriterFilter#2c2a7d53, org.springframework.security.web.csrf.CsrfFilter#b9b97ad, org.springframework.security.web.authentication.logout.LogoutFilter#29f3185c, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#4ffa7041, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter#2c2a903f, org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter#6c70b7c3, org.springframework.security.web.authentication.www.BasicAuthenticationFilter#48d44b46, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#5cbe95b1, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#11ad095c, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#16a09809, org.springframework.security.web.session.SessionManagementFilter#1de85972, org.springframework.security.web.access.ExceptionTranslationFilter#4a122e68, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#5d37aa0f]
2019-11-05 14:33:32.392 INFO 39079 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-11-05 14:33:32.398 INFO 39079 --- [ main] eModelDeploymentServiceParentApplication : Started ServiceModelDeploymentServiceParentApplication in 5.727 seconds (JVM running for 6.778)
Here are my pom 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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</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>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Note: You may be not needing all the dependencies above.
Adding spring boot starter web solved my problem
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Add the below dependencies in pom.xml :
<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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>test</scope>
</dependency>
If you create a project gradle template from https://start.spring.io/ (sprint initializr), you need to add org.springframework.boot:spring-boot-starter-web dependecy in you build.gradle file.
// you need to add this dependency to run spring boot correctly
implementation 'org.springframework.boot:spring-boot-starter-web'
Using the below dependencies in pom.xml, as well as loading maven changes (ctrl+shift+o) solved my problem.
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
in my case i started intelliJ as
adminstrator
, then it works
make sure you have tomcat dependency
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>9.0.29</version>
</dependency>
In my case, there is a slight difference between:
Just click Run in the most visible bottom inside IntelliJ and...
Look for the default controller inside src/main/java/com.exampler.yourapplication, right click and press Run there.
The second option just run the project properly.
If below property was added to the allication.properties file, need to remove this.
This property is used to remove the web container.
spring.main.web-application-type=none
In my case I forgot to remove this and once it's removed the issue was fixed
In my case, I need to remove several dependencies first. Then I run maven clean. After that my code just works fine.

Categories