Issue
I'm having trouble getting my spring-boot application working. It's just exposing a single endpoint at the moment. And it's just got a single controller to manage that. Here is the code below.
It builds fine and the tomcat server runs, I get the Whitelabel Error Page.
Full error from chrome console: Failed to load resource: the server responded with a status of 404.
src
--|main
----|java
------|com.domain.myproject.api
--------|Controller <----(this is a package in intellij)
----------|RestController.java
--------|Springboot <----(this is a package in intellij)
----------|SpringApplication.java
RESTController.java
package com.example.myproject.api.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class RESTController {
@GetMapping("/view/{id}")
public String hello (@PathVariable("id") String id){
return "return" + id;
}
}
SpringApplication.java
package com.example.myproject.api.Springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class CustomsApiApplication {
public static void main(String[] args) {
SpringApplication.run(CustomsApiApplication.class, args);
}
}
pom-xml
These are the dependencies, which I will get to use.
<dependencies>
<!--SpringBoot Dependencies-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Camel dependencies -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.20.1</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jms</artifactId>
<version>2.20.1</version>
</dependency>
<!-- ActiveMQ dependencies -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-client</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
</dependency>
</dependencies>
Thanks!
PS. Also get in the intellij run console. . .
2018-01-23 18:28:14.879 ERROR 10541 --- [nio-8080-exec-1]
o.s.d.r.w.RepositoryRestExceptionHandler : Could not resolve repository
metadata for 1234.
Solution
According to Spring boot documentation 14.2 Locating the main application class, it is recommended that you locate your main application class in a root package above other classes.
The @EnableAutoConfiguration
annotation is often placed on your main class, and it implicitly defines a base “search package” for certain items. Using a root package also allows the @ComponentScan
annotation to be used without needing to specify a basePackage attribute. Both these annotations are defined within @SpringBootApplication
.
Answered By - Luay Abdulraheem
Answer Checked By - Willingham (JavaFixing Volunteer)