'Tomcat server not finding representations of endpoints

I am creating gradle Spring MVC project without Spring-Boot, and for some reason when I run Tomcat server doesn't see the endpoint in my controller class.

My controller is very simple just to test if it works:

@RestController
public class CertificateController {

    @GetMapping("/home")
    public String getAllCertificates() {
        return "try";
    }
}

My Spring Configuration class:

@Configuration
@ComponentScan(basePackages = "com.epam.esm")
@EnableWebMvc
public class ApplicationConfig implements WebMvcConfigurer {

    private final ApplicationContext applicationContext;

    @Autowired
    public ApplicationConfig(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    @Bean
    public SpringResourceTemplateResolver templateResolver() {
        SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
        templateResolver.setApplicationContext(applicationContext);
        templateResolver.setPrefix("/WEB-INF/views/");
        templateResolver.setSuffix(".html");
        return templateResolver;
    }

    @Bean
    public SpringTemplateEngine templateEngine() {
        SpringTemplateEngine templateEngine = new SpringTemplateEngine();
        templateEngine.setTemplateResolver(templateResolver());
        templateEngine.setEnableSpringELCompiler(true);
        return templateEngine;
    }

    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        ThymeleafViewResolver resolver = new ThymeleafViewResolver();
        resolver.setTemplateEngine(templateEngine());
        registry.viewResolver(resolver);
    }
}

My Initializer class:

public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return null;
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{ApplicationConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }
}

The project itself is multi-module: API module for application configuration and controllers and CORE module for program logic which is currently empty.

To the server, I give the root project artifact. Root project gradle.build:

plugins {
    id 'war'
    id 'java'
    id 'application'
}

subprojects {
    project(':api') {
        apply plugin: 'application'
        apply plugin: 'java'
        apply plugin: 'war'
    }

    project(':core') {
        apply plugin: 'java'
    }

    repositories {
        mavenCentral()
    }

    java {
        sourceCompatibility(11)
        targetCompatibility(11)
    }

    dependencies {
        implementation 'org.springframework:spring-web:5.3.15'
        implementation 'org.springframework:spring-webmvc:5.3.15'
        implementation 'org.springframework:spring-context:5.3.15'
        implementation 'org.springframework:spring-jdbc:5.3.15'

        implementation 'org.thymeleaf:thymeleaf-spring5:3.0.13.RELEASE'

        implementation 'javax.servlet:javax.servlet-api:4.0.1'

        implementation 'org.postgresql:postgresql:42.1.4'
        implementation 'com.zaxxer:HikariCP:2.3.2'

        implementation 'org.apache.logging.log4j:log4j-api:2.16.0'

        testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
        testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
        testImplementation 'org.mockito:mockito-core:2.1.0'
        testImplementation 'com.h2database:h2:1.3.148'
    }
}


test {
    useJUnitPlatform()
}

The server loads fine but when I try to access the endpoint it says:

The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source