Search code examples
springsecuritycontroller

Spring Boot, controller and my securityConfig files are never used


my name is Andre. I created a Spring Boot Web Application Project and my problem is that both my controller and my securityConfig files are never used (IntelliJ tells me so). I am using Spring Boot 3.3 on Windows 11. Google tells me to place my main app file in the base package and to have my controllers in sub packages below the base package but this does not work. I am already using

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

in the pom.xml file.

When I run my application, the index.html comes up just fine (note: I am using traditional HTML files and NOT thymeleaf). My login form is on this index.html page. I enter the proper credentials and the browser displays a mixture of the home.html page and the error.html page. My Ajax file tries to run but fails to find an endpoint called "loggInUser" because the method "patty" used to call the loggInUser() method never gets called because the class UserController is never used according to IntelliJ.


Solution

  • After looking to your source code available, I see your class DataController is not annotated with @RestController or @Controller and that is why Spring cannot map all the endpoints included in that class (including @GetMapping("/loggInUser")).

    Besides that, I would recommend you to look at best practices when autowiring in Spring. Ideally you do autowiring always in the constructor instead of on private fields, as it makes your code more testable.