I am trying to deploy a Spring Boot Application on Tomcat11, but I am getting a 404 error when sending requests to valid endpoint.
I am using Java 21, Spring Boot 3.3.0 on Tomcat 11 with port 8082.
My application.properties file:
`cors.allowed-origins=http://localhost:3000
cors.allowed-headers=*
cors.allow-credentials=true
cors.allowed-methods=GET,POST,PUT,DELETE,OPTIONS
spring.application.name=ivr-test-automation-backend
server.port=8082
spring.datasource.url=jdbc:postgresql://POSTGREIP:5432/ivr_test
spring.datasource.username=test_app
spring.datasource.password=password
spring.datasource.hikari.schema=ivr_test_automation
spring.datasource.driver-class-name=org.postgresql.Driver
spring.sql.init.mode=always
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
logging.level.org.springframework.web.reactive.function.client=WARN
logging.level.org.springframework=WARN
logging.level.root=WARN
logging.level.org.hibernate=WARN
logging.file.name=logs/ivr-test-automation-backend.log
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.format_sql=true
# JWT
remote.auth.url=http://LDAPIP:992/api/v1/authenticate/login
remote.auth.secret=IVRLdap-Password
#jwt.secret=ivrTestAutomationSecret
jwt.expiration=36000000
jwt.secret = ${jwt.secret}
spring.devtools.restart.enabled=true
spring.devtools.livereload.enabled=true`
My AuthController
@RestController
@RequestMapping("/api/v1/auth")
public class AuthController {
.
.
.
@PostMapping("/login")
public ResponseEntity<RestResponse<JwtAuthenticationResponse>> createAuthenticationToken(@RequestBody LoginRequest authRequest) throws Exception {
authenticationManager.authenticate(
new UsernamePasswordAuthenticationToken(authRequest.ldapName(), authRequest.password())
);
final UserDetails userDetails = userDetailsService.loadUserByUsername(authRequest.ldapName());
final String jwt = jwtUtil.generateToken(userDetails);
JwtAuthenticationResponse jwtAuthenticationResponse = getJwtAuthenticationResponse(authRequest.ldapName(), jwt);
return ResponseEntity.ok(RestResponse.of(jwtAuthenticationResponse, AuthMessage.SUCCESSFUL_LOGIN));
}
.
.
.
}
I am making the endpoint public with the following code block.
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http, JwtTokenRefreshFilter jwtTokenRefreshFilter) throws Exception {
http.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(auth -> auth
.requestMatchers("/api/v1/auth/**").permitAll()
.requestMatchers("/v3/api-docs/**", "/swagger-ui/**", "/swagger-ui.html").permitAll()
.requestMatchers("/api/v1/role/**").authenticated()
.requestMatchers("/api/v1/user/**").authenticated()
.requestMatchers("/api/v1/permission/**").authenticated()
.requestMatchers("/api/v1/blacklist/**").authenticated()
.requestMatchers("/api/v1/scenario-configuration/**").authenticated()
.requestMatchers("/api/v1/scenario-configuration-history/**").authenticated()
.anyRequest().authenticated())
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authenticationProvider(customAuthProvider())
.addFilterBefore(jwtTokenRefreshFilter, UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class)
.logout(logout -> logout
.logoutUrl("/api/v1/auth/logout")
.logoutSuccessHandler((request, response, authentication) -> {
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().write(AuthMessage.SUCCESSFUL_LOGOUT.getMessage());
}));
return http.build();
}
On tomcat in server.xml file I added the Connector port for 8082
<Connector port="8082" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
When i run netstat -aon
, the port is listening:
tcp6 0 0 :::8080 :::* LISTEN off (0.00/0/0)
tcp6 0 0 :::8081 :::* LISTEN off (0.00/0/0)
tcp6 0 0 :::8082 :::* LISTEN off (0.00/0/0)
These are my settings. When I send a request on http://SERVERIP:8082/api/v1/auth/login via postman, I get the following error.
The application seems to be running successfully in the logs on catalina.out.
Example log that show deployment is success:
05-Sep-2024 19:43:57.201 INFO [Catalina-utility-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/opt/tomcat/webapps/ivr-test-automation-backend-0.0.1-SNAPSHOT.war] has finished in [11,316] ms
What could be causing this 404 error for a valid endpoint, and how can I fix it? If there is any config setting you want me to show, I can show it.
Any help would be appreciated!
I tried to add address="0.0.0.0"
to the server.xml file.
<Connector port="8082" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
address="0.0.0.0" />
Then it took this form. The resuld did not change.
And when i tried sudo firewall-cmd –list-all, shows me.
[root@S200OUT03 logs]# sudo firewall-cmd --list-all
FirewallD is not running
5