0

I have looked on Stack Overflow a few days ago. My problem seems to be very common, but I cannot manage to fix it.

I've tried these ways 1 and 2.

This is my application.propreties :

spring.datasource.driver-class-name= org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5433/mydatabase
spring.datasource.username=username
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=create
spring.main.web-application-type=none

When I tried to run it, it is giving me following errors :

org.springframework.context.ApplicationContextException: Unable to start web server; 
nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean

These is my main class:

@SpringBootApplication
public class StartApplication {

    @Autowired
    BookRepository repository;

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

and this 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>toto</groupId>
    <artifactId>toto</artifactId>
    <version>1.0-SNAPSHOT</version>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
    </parent>
    <properties>
        <java.version>1.8</java.version>
        <downloadSources>true</downloadSources>
        <downloadJavadocs>true</downloadJavadocs>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.1.6.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.0</version>
            </plugin>
        </plugins>
    </build>
</project>

Thanks in advance for your help.

Giorgi Tsiklauri
  • 9,715
  • 8
  • 45
  • 66
louison
  • 1
  • 3

3 Answers3

0

You should remove the following property from your application.properties file

spring.main.web-application-type=none

it means that you don't need a web server in your application.

Elgayed
  • 1,129
  • 9
  • 16
  • Okay i did but a new error appeared : Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.2.RELEASE:run (default-cli) on project toto: An exception occurred while running. null: InvocationTargetException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean. -> [Help 1] – louison Jul 24 '19 at 07:44
0

I'm not a pro programmer, but what I would do if I were you :

  1. Make sure you have a proper project structer
  2. Check the basic configuration guides fromSpring.io!

I have my personal project where I training with Spring Framework usage, maybe you will get something usefull from it,project link!

Good luck and have fun :)

0

Your main class should be like:

@SpringBootApplication
public class StartApplication {
    
    @Autowired
    BookRepository repository;
    
    public static void main(String[] args) {
        SpringApplication.run(StartApplication.class, args);
    }
}
Giorgi Tsiklauri
  • 9,715
  • 8
  • 45
  • 66
rakeeee
  • 973
  • 4
  • 19
  • 44