Thanos M
Thanos M

Reputation: 673

Spring boot application is starting normally on tomcat 8 locally but i am getting 404

My spring boot application is starting normally without a single error or warning, i see all URL mappings in my console like that :

2019-01-25 13:26:56.157 INFO 1020 --- [ost-startStop-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/auth/userAccessToken],methods=[POST]}" onto public java.lang.String com.test.garmin.controller.OAuthController.generateToken(java.lang.Long,java.lang.String,org.springframework.ui.Model)

and i see the initialization is completed :

2019-01-25 14:25:57.714 INFO 21244 --- [ost-startStop-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'measurementrest': initialization completed in 4175 ms

When i try to use my webservices all i get is 404 not found.

Packages look like that project packages , packages containing controllers have a red line.

my application class :

@Configuration
@ComponentScan(basePackages ={"com.test.garmin.controller","com.test.measurement.ws"})
@EntityScan
@EnableAutoConfiguration
public class Application extends SpringBootServletInitializer {

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

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

    private static Class<Application> applicationClass = Application.class;
}

controllers are annotated like that :

@RestController
@EnableAutoConfiguration
@RequestMapping(value = "/example")

servlet.xml file :

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
    <mvc:annotation-driven/>
    <context:component-scan base-package="com.test.garmin.controller , com.test.measurement.ws" />
</beans>

I can't find where i am wrong. Most of the threads i have found insist that this is a packages problem, but i have declared my packages in application class. Any ideas?

Upvotes: 0

Views: 180

Answers (3)

Thanos M
Thanos M

Reputation: 673

The mistake was not obvious at least not for me. The artifact name was wrong, so it was deployed in tomcat webapps with name MeasurementService_war.war while my context.xml was like that

<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/MeasurementService"/>

Thats why i was getting a 404 error not found

Upvotes: 0

Sai prateek
Sai prateek

Reputation: 11906

Looks like api /auth/userAccessToken is mapped properly but you are trying to access wrong url. Please try the url like below in postman or any rest client tool with POST method with required parameters-

http://localhost:8080/your_project_context/example/auth/userAccessToken

Upvotes: 0

vavasthi
vavasthi

Reputation: 952

404 maps to not found. Please provide the URL that your client is using and also a complete code of controller. At least all the method signatures.

Upvotes: 0

Related Questions