0

I'm using Ubuntu; I installed Java & jdk :

user@CU-Desktop:~$ java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode)
user@CU-Desktop:~$ javac -version
javac 11.0.11

I generate spring boot project from spring initializr, this is the poom.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.5.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.test</groupId>
    <artifactId>testproject</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>testproject</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>11</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-data-rest</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-web</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </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.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>

Main class :

@SpringBootApplication
public class TestprojectApplication {

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

}

Servlet initializer :

public class ServletInitializer extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(TestprojectApplication.class);
    }

}

Next I create a basic entity :

@Entity
@Table(name = "CpAccount")
public class Account {

    @Id
    @Column(name = "Id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name = "Login")
    private String login;

    @Column(name = "Password")
    private String password;

    @Column(name = "Email")
    private String email;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
}

And set configuration for DB access on application.properties :

spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql:localhost:3306/project_db
spring.datasource.username=myusername
spring.datasource.password=mypassword

The problem is when I launch tomcat, it doesn't launch Spring. The log just notify that tomcat is successfully launched :

Aug 26, 2021 11:25:44 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in [320] milliseconds
UglyCow
  • 21
  • 3
  • 1
    Which tomcat version. – M. Deinum Aug 26 '21 at 10:30
  • You don't give any information on how did you deploy your application. Did you build a WAR file and deploy it in `$CATALINA_BASE/webapps`? Did you use another method? – Piotr P. Karwasz Aug 26 '21 at 10:39
  • I'm using Tomcat 10.0.8. Actually is an IDE project, I'm using Intellij community. I use "Smart Tomcat" plugin to configure deployment on tomcat – UglyCow Aug 26 '21 at 10:40
  • For spring boot application, you don't need to run separate tomcat. Just right click on SpringBootApplication class and select run as Java Application. It will start application on an embedded tomcat server. – Hemant Patel Aug 26 '21 at 12:34
  • I know that I can launch it without tomcat, but I want to develop a web app, so need that works on tomcat. Piotr thank you very match, that was it. It doesn't work with tomcat 10.xx but works well with tomcat 9.xx – UglyCow Aug 26 '21 at 12:57

0 Answers0