2

I am developing a simple Spring Boot base rest application which has been deployed into an external tomcat server, with jndi data source. When I run the application the database gets created, this means the application is able to read the Entity classes and create hibernate ddl. However, when I try to hit the rest url from postman a 404 error message is returned. This has happened after I have moved my application to an external server, when I was using the embeded server I was able to hit the urls. Can someone help me figure out what am I doing wrong?

Main method:

package com.nb;

@SpringBootApplication
public class SpringBootWithSpringDataJpaApplication extends SpringBootServletInitializer{

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

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

Controller:
package com.nb.springboot.topic;
@RestController
public class TopicController {

@Autowired
private TopicService topicService;

    @RequestMapping("/topics")
    public List<Topic> getAllTopics(){
        return topicService.getAllTopics();
    }

    @RequestMapping("/topics/{id}")
    public Topic getTopic(@PathVariable("id") String id){
        return topicService.getTopic(id);
    }

    @RequestMapping(method=RequestMethod.POST, value="/topics")
    public void addTopic(@RequestBody Topic topic){
        topicService.addTopic(topic);

    }

    @RequestMapping(method=RequestMethod.PUT, value="/topics/{id}")
    public void updateTopic(@RequestBody Topic topic, @PathVariable String id){
        topicService.updateTopic(topic, id);
    }

    @RequestMapping(method=RequestMethod.DELETE, value="/topics/{id}")
    public void deleteTopic(@PathVariable String id){
        topicService.deleteTopic(id);
    }

}

http://localhost:8080/topics/java ---- works with embedded server

http://localhost8080/topics/java ------ does not work in tomcat 8(external)

http://localhost8080/SpringBootWithSpringDataJPA/topics/java ------ does not work in tomcat 8(external) where SpringBootWithSpringDataJPA is my project name.

The application.properties file is :

spring.datasource.jndi-name=java:/comp/env/jdbc/postgres/springbootDS

spring.jpa.hibernate.ddl-auto=create

spring.jpa.show-sql=true

3
  • I suspect it is because when you deploy to an external server it is actually deployed into a web context. Open the tomcat manager to see what the context is, your url will look like localhost:8080{context}/topics/java Commented Jan 9, 2017 at 17:27
  • 1
    If you use maven its most (if dont changed the version) something like localhost:8080/SpringBootWithSpringDataJPA-0.0.1-SNAPSHOT/... Commented Jan 9, 2017 at 18:16
  • Ohh Thank you so much. I am using maven and the war that gets generated has name SpringBootWithSpringDataJPA-0.0.1-SNAPSHOT. I forgot to change the name. Guess this was dumb! Thanks ton!! Commented Jan 10, 2017 at 9:30

1 Answer 1

3

Sounds like you are missing the app name in the url, like:

localhost:8080/appname/topics/java

or if you use maven should be:

localhost:8080/appnameX.X.X-SNAPSHOT/topics/java...
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! That was the issue with the url call, I am using maven so war gets generated with X.X.X-SNAPSHOT. Totally missed it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.