Issue
I am using Spring security in my application for encrypting user password in database. Due to this I am getting Using generated security password:XXXXXX in my Spring boot log when starting application. I didn't want this password to be generated so I am using @SpringBootApplication (exclude = {SecurityAutoConfiguration.class }) in my main class. Below is my main class
package com.example.policymanagementsystem;
import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication (exclude = {SecurityAutoConfiguration.class })
@ComponentScan( basePackages = {"com.example.policymanagementsystem.bean"})
public class PolicymanagementsystemApplication {
public static void main(String[] args) {
SpringApplication.run(PolicymanagementsystemApplication.class, args);
}
}
So the password is not getting generated when starting spring boot application but when I hit api from postman it is giving me 404 Not found error for all other api's. I don't want authentication to any of my api's so I have given below configuration in the SecurityConfiguration class.
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and().csrf().disable();
http.authorizeRequests().antMatchers("/admin/**").permitAll().antMatchers("/user/**").permitAll().anyRequest().authenticated();
http.exceptionHandling()
.authenticationEntryPoint(
(request, response, ex) -> {
response.sendError(
HttpServletResponse.SC_UNAUTHORIZED,
ex.getMessage()
);
}
);
http.addFilterBefore(jwtTokenFilter, UsernamePasswordAuthenticationFilter.class);
}
Please suggest me some way so that I can exclude SecurityAutoConfiguration.class and not get 404 not found error in my postman response for any api.Thanks in advance!!
Solution
I found a solution for it, the 404 not found error was because I didn't annotated field in one of my model class with @Id annotation. It's resolved now.
Answered By - Diptesh karle
Answer Checked By - Mary Flores (JavaFixing Volunteer)