Reputation: 904
I have this service in github https://github.com/felloz/personsService The application compile with no errors but when im trying to access the route http://localhost:8080/demo/persons Im getting this error:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon May 11 14:55:30 VET 2020
There was an unexpected error (type=Not Found, status=404).
No message available
The compile message:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.7.RELEASE)
2020-05-11 15:05:55.576 INFO 10476 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication on lserrano-PC with PID 10476 (C:\JAVA\Eclipse Projects\demo\target\classes started by lserrano in C:\JAVA\Eclipse Projects\demo)
2020-05-11 15:05:55.592 INFO 10476 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2020-05-11 15:05:58.173 INFO 10476 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-05-11 15:05:58.198 INFO 10476 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-05-11 15:05:58.198 INFO 10476 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.34]
2020-05-11 15:05:58.386 INFO 10476 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-05-11 15:05:58.387 INFO 10476 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2685 ms
2020-05-11 15:05:58.857 INFO 10476 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
2020-05-11 15:05:59.362 INFO 10476 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-05-11 15:05:59.377 INFO 10476 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 4.578 seconds (JVM running for 5.433)
2020-05-11 15:06:14.712 INFO 10476 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-05-11 15:06:14.712 INFO 10476 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2020-05-11 15:06:14.727 INFO 10476 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 15 ms
You can check the code in the github repo, Im new with Sprong any help will be appreciated, im using NetBeans as IDE.
After adding server.servlet.context-path=/demo
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.7.RELEASE)
2020-05-11 17:26:54.336 INFO 9144 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication on lserrano-PC with PID 9144 (C:\JAVA\Eclipse Projects\demo\target\classes started by lserrano in C:\JAVA\Eclipse Projects\demo)
2020-05-11 17:26:54.336 INFO 9144 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2020-05-11 17:26:56.926 INFO 9144 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-05-11 17:26:56.957 INFO 9144 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-05-11 17:26:56.957 INFO 9144 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.34]
2020-05-11 17:26:57.160 INFO 9144 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/demo] : Initializing Spring embedded WebApplicationContext
2020-05-11 17:26:57.160 INFO 9144 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2715 ms
2020-05-11 17:26:57.612 INFO 9144 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
2020-05-11 17:26:58.111 INFO 9144 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '/demo'
2020-05-11 17:26:58.111 INFO 9144 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 4.591 seconds (JVM running for 5.464)
2020-05-11 17:27:14.361 INFO 9144 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/demo] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-05-11 17:27:14.362 INFO 9144 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2020-05-11 17:27:14.379 INFO 9144 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 17 ms
Upvotes: 0
Views: 7275
Reputation: 723
If you don't want to use Jpa, following changes would be needed :
Context Path
should be set as:
server.servlet.context-path=/demo
DemoApplication
Class (correcting base package):
@SpringBootApplication
@ComponentScan(basePackages = {"com.example"})
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
You need to provide the implementation for your Repositoory
:
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Repository;
@Repository
public class PersonRepository{
public List<Person> findAll(){
List<Person> list = new ArrayList<>();
Person person = new Person();
person.setId(10001);
person.setName("Name");
person.setLastname("LastName");
list.add(person);
return list;
}
}
To work with MySQL DB and SpringBoot , you can find many example on web. Please follow that. Example : SpringBootMySQLExample
Upvotes: 1
Reputation: 154
after spring 2 , context path configuration has been changed ;
server.servlet.context-path=/demo
And then try http://localhost:8080/demo/persons
Upvotes: 1
Reputation: 643
you have @RequestMapping({"/persons"})
in your controller, so try this link http://localhost:8080/persons
without demo
Upvotes: 1