Spring Boot 404 when calling trying to browse to rest controller - java
I have seen many similar problems on here but none of them seem to be the solution for me. My package structure seems to be correct and even if it wasn't, explicitly declaring the package or #RestController class in the application class still results in a 404. One thing I have noticed different about my problem than most others I have seen is that I am getting an HTML 404 response while most others I've seen are getting JSON 404 responses. I am not deploying this application, just running with mvn spring-boot:run.
Here is my code:
package com.billbuddy;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class BillbuddyApplication {
public static void main(String[] args) {
SpringApplication.run(BillbuddyApplication.class, args);
}
}
Adding the annotation #ComponentScan(#ComponentScan(basePackageClasses = UserController.class) still results in the 404
Here is my rest controller class
package com.billbuddy.controllers;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
#RestController
#RequestMapping("/user")
public class UserController {
#RequestMapping("/login")
public String login() {
return "Hello, World";
}
}
As you can see my Rest controller is in a nested class of the Spring application class. The folder structure is the same
- src/main/java
- com/billbuddy
- BillbuddyApplication.java
- controllers
- UserController.java
Here is my pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.testprojects</groupId>
<artifactId>billbuddy</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>billbuddy</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-couchbase</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Here is what my output looks like when running the command (external IP of my CouchBase host [connection initialized but not yet used by my spring-boot application] has been censored and appears as XXX.XXX.XXX.XXX).
2018-12-22 06:11:42.603 INFO 56870 --- [ main] com.billbuddy.BillbuddyApplication : Starting BillbuddyApplication on charlies-mbp.lan with PID 56870 (/Users/user1/Projects/Github/angular-example/Server/target/classes started by user1 in /Users/user1/Projects/Github/angular-example/Server)
2018-12-22 06:11:42.608 INFO 56870 --- [ main] com.billbuddy.BillbuddyApplication : No active profile set, falling back to default profiles: default
2018-12-22 06:11:43.737 INFO 56870 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2018-12-22 06:11:43.921 INFO 56870 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 172ms. Found 1 repository interfaces.
2018-12-22 06:11:44.702 INFO 56870 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2018-12-22 06:11:44.736 INFO 56870 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-12-22 06:11:44.736 INFO 56870 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/9.0.13
2018-12-22 06:11:44.749 INFO 56870 --- [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/Users/user1/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.]
2018-12-22 06:11:44.840 INFO 56870 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-12-22 06:11:44.840 INFO 56870 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2130 ms
2018-12-22 06:11:45.345 INFO 56870 --- [ main] com.couchbase.client.core.CouchbaseCore : CouchbaseEnvironment: {sslEnabled=false, sslKeystoreFile='null', sslTruststoreFile='null', sslKeystorePassword=false, sslTruststorePassword=false, sslKeystore=null, sslTruststore=null, bootstrapHttpEnabled=true, bootstrapCarrierEnabled=true, bootstrapHttpDirectPort=8091, bootstrapHttpSslPort=18091, bootstrapCarrierDirectPort=11210, bootstrapCarrierSslPort=11207, ioPoolSize=4, computationPoolSize=4, responseBufferSize=16384, requestBufferSize=16384, kvServiceEndpoints=1, viewServiceEndpoints=12, queryServiceEndpoints=12, searchServiceEndpoints=12, configPollInterval=2500, configPollFloorInterval=50, networkResolution=NetworkResolution{name='auto'}, ioPool=NioEventLoopGroup, kvIoPool=null, viewIoPool=null, searchIoPool=null, queryIoPool=null, analyticsIoPool=null, coreScheduler=CoreScheduler, memcachedHashingStrategy=DefaultMemcachedHashingStrategy, eventBus=DefaultEventBus, packageNameAndVersion=couchbase-java-client/2.7.1 (git: 2.7.1, core: 1.7.1), retryStrategy=BestEffort, maxRequestLifetime=75000, retryDelay=ExponentialDelay{growBy 1.0 MICROSECONDS, powers of 2; lower=100, upper=100000}, reconnectDelay=ExponentialDelay{growBy 1.0 MILLISECONDS, powers of 2; lower=32, upper=4096}, observeIntervalDelay=ExponentialDelay{growBy 1.0 MICROSECONDS, powers of 2; lower=10, upper=100000}, keepAliveInterval=30000, continuousKeepAliveEnabled=true, keepAliveErrorThreshold=4, keepAliveTimeout=2500, autoreleaseAfter=2000, bufferPoolingEnabled=true, tcpNodelayEnabled=true, mutationTokensEnabled=false, socketConnectTimeout=1000, callbacksOnIoPool=false, disconnectTimeout=25000, requestBufferWaitStrategy=com.couchbase.client.core.env.DefaultCoreEnvironment$4#5d52e3ef, certAuthEnabled=false, coreSendHook=null, forceSaslPlain=false, compressionMinRatio=0.83, compressionMinSize=32, compressionEnabled=true, operationTracingEnabled=true, operationTracingServerDurationEnabled=true, tracer=ThresholdLogTracer, orphanResponseReportingEnabled=true, orphanResponseReporter=DefaultOrphanResponseReporter, keyValueServiceConfig=KeyValueServiceConfig{minEndpoints=1, maxEndpoints=1, pipelined=true, idleTime=0}, queryServiceConfig=QueryServiceConfig{minEndpoints=1, maxEndpoints=1, pipelined=false, idleTime=300}, searchServiceConfig=SearchServiceConfig{minEndpoints=0, maxEndpoints=12, pipelined=false, idleTime=300}, viewServiceConfig=ViewServiceConfig{minEndpoints=1, maxEndpoints=1, pipelined=false, idleTime=300}, analyticsServiceConfig=AnalyticsServiceConfig{minEndpoints=0, maxEndpoints=12, pipelined=false, idleTime=300}, queryTimeout=7500, viewTimeout=7500, searchTimeout=75000, analyticsTimeout=75000, kvTimeout=2500, connectTimeout=5000, dnsSrvEnabled=false, propagateParentSpan=true}
2018-12-22 06:11:46.672 INFO 56870 --- [ cb-io-1-1] com.couchbase.client.core.node.Node : Connected to Node XXX.XXX.XXX.XXX/XXX.XXX.XXX.XXX
2018-12-22 06:11:46.796 INFO 56870 --- [-computations-4] c.c.c.core.config.ConfigurationProvider : Selected network configuration: default
2018-12-22 06:11:46.810 INFO 56870 --- [-computations-4] c.c.c.core.config.ConfigurationProvider : Opened bucket BillBuddy
2018-12-22 06:11:47.394 INFO 56870 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-12-22 06:11:47.398 INFO 56870 --- [ main] com.billbuddy.BillbuddyApplication : Started BillbuddyApplication in 5.436 seconds (JVM running for 6.733)
2018-12-22 06:12:25.329 WARN 56870 --- [ cb-orphan-1] c.c.c.c.t.DefaultOrphanResponseReporter : Orphan responses observed: [{"top":[{"r":"XXX.XXX.XXX.XXX:8092","s":"view","c":"09F46A832158B8F9/0000000037386FDF","l":"192.168.86.142:62096"}],"service":"view","count":1}]
I am testing the #RestController by browsing to http://localhost:8080/user/login in chrome and see the following screen:
https://imgur.com/a/42U3eZR
Running
curl http://localhost:8080/user/login
Returns
<!doctype html><html lang="en"><head><title>HTTP Status 404 – Not Found</title><style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 404 – Not Found</h1></body></html>
I'm sure it's going to be something stupid I'm doing, but I've tried dozens of other answers I've seen both on stack overflow and other websites to no avail. Please help me.
Made a quick test with a project on my pc... you should have in your pom this dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
let me know if it works.
Related
How to solve this Spring Boot Whitelabel error
im building CRUD app but ran into a problem . When I start the application at http://localhost:8080/api/v1/employees i recieve a whitelabel error 404 instead JSON response with db data . Message This application has no explicit mapping for /error, so you are seeing this as a fallback. Thu Sep 08 17:49:26 GST 2022 There was an unexpected error (type=Not Found, status=404). No message available Controller package com.crudpet.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.crudpet.model.Employee; import com.crudpet.repository.EmployeeRepository; #RestController #RequestMapping("/api/v1/") public class EmployeeController { #Autowired private EmployeeRepository employeeRepository; #GetMapping("/employees") public List<Employee> getAllEmployees(){ return employeeRepository.findAll(); } } main class package com.crudpet.springboot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; #SpringBootApplication public class SpringbootBackendCrudApplication { public static void main(String[] args) { SpringApplication.run(SpringbootBackendCrudApplication.class, args); } } console 2022-09-08 17:49:19.486 INFO 836 --- [ restartedMain] c.c.s.SpringbootBackendCrudApplication : Starting SpringbootBackendCrudApplication using Java 17.0.1 on DESKTOP-08M3S29 with PID 836 (C:\Users\Bogich\Documents\workspace-spring-tool-suite-4-4.13.1.RELEASE\springboot-backend-crud\target\classes started by Bogich in C:\Users\Bogich\Documents\workspace-spring-tool-suite-4-4.13.1.RELEASE\springboot-backend-crud) 2022-09-08 17:49:19.487 INFO 836 --- [ restartedMain] c.c.s.SpringbootBackendCrudApplication : No active profile set, falling back to 1 default profile: "default" 2022-09-08 17:49:19.556 INFO 836 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable 2022-09-08 17:49:19.556 INFO 836 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG' 2022-09-08 17:49:20.206 INFO 836 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode. 2022-09-08 17:49:20.223 INFO 836 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 7 ms. Found 0 JPA repository interfaces. 2022-09-08 17:49:20.833 INFO 836 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2022-09-08 17:49:20.844 INFO 836 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2022-09-08 17:49:20.844 INFO 836 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.65] 2022-09-08 17:49:20.917 INFO 836 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2022-09-08 17:49:20.917 INFO 836 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1360 ms 2022-09-08 17:49:21.132 INFO 836 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default] 2022-09-08 17:49:21.193 INFO 836 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.10.Final 2022-09-08 17:49:21.388 INFO 836 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final} 2022-09-08 17:49:21.507 INFO 836 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... 2022-09-08 17:49:21.684 INFO 836 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed. 2022-09-08 17:49:21.701 INFO 836 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect 2022-09-08 17:49:21.988 INFO 836 --- [ restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform] 2022-09-08 17:49:21.999 INFO 836 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default' 2022-09-08 17:49:22.063 WARN 836 --- [ restartedMain] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning 2022-09-08 17:49:22.450 INFO 836 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729 2022-09-08 17:49:22.492 INFO 836 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '' 2022-09-08 17:49:22.502 INFO 836 --- [ restartedMain] c.c.s.SpringbootBackendCrudApplication : Started SpringbootBackendCrudApplication in 3.407 seconds (JVM running for 4.229) 2022-09-08 17:49:26.819 INFO 836 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet' 2022-09-08 17:49:26.819 INFO 836 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2022-09-08 17:49:26.820 INFO 836 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.3</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.crudpet</groupId> <artifactId>springboot-backend-crud</artifactId> <version>0.0.1-SNAPSHOT</version> <name>springboot-backend-crud</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> The problem is when i start app i must recieve a JSON response but i see Whitelabel error. I've tried ComponentScan , but it is not work for me. What i must do?
You haven't specified the package name in your controller and main classes. The default Spring auto-discovery won't work because of this, and your controller won't be instantiated. Spring looks for the components under the packages specified classes. Without the specified package, Spring won't be able to 'see' your beans and add them to ApplicationContext. Simply add the package statement at the top of your class and everything should start working correctly. Example: package com.example; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.crudpet.model.Employee; import com.crudpet.repository.EmployeeRepository; #RestController #RequestMapping("/api/v1/") public class EmployeeController { #Autowired private EmployeeRepository employeeRepository; #GetMapping("/employees") public List<Employee> getAllEmployees(){ return employeeRepository.findAll(); } } Updated: Your main class SpringbootBackendCrudApplication, which is marked as #SpringBootApplication is located in the package com.crudpet.springboot. Whereas your controller is located in the com.crudpet.controller package. By default, Spring Boot will scan for beans in the base package of the class with main method (SpringbootBackendCrudApplication in your case) and all nested packages (e.g., com.crudpet.springboot.example). The com.crudpet.controller package with your controller class is out of scope and simply wasn't initiated. To fix this, you need to place the SpringbootBackendCrudApplication class in the com.crudpet package, which is best practice. Another possible solution is explicitly specifying the com.crudpet.controller package in the component scan.
Unable to access rest api using Postman for Spring Boot Application with Mongodb
I am trying to create a Spring Boot API, but I am not getting anything in my logs and U am unable to access using Postman and cURL. Even "hello world" example is also not running. Changing port did not work as different ports need to be allocated for different services and in my scenario port 8080 is for tomcat and 8081 for mongo-express. <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.5.3</version> <relativePath/> <!-- lookup parent from com.example.quiz.repository --> </parent> <groupId>com.example</groupId> <artifactId>quiz</artifactId> <version>0.0.1-SNAPSHOT</version> <name>quiz</name> <description>quiz project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <excludes> <exclude> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </exclude> </excludes> </configuration> </plugin> </plugins> </build> </project> QuizApplication.java package com.example.quiz; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; #SpringBootApplication #RestController public class QuizApplication { public static void main(String[] args) { SpringApplication.run(QuizApplication.class, args); } } Question.java package com.example.quiz.model; import lombok.Data; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; #Data #Document(collection = "question") public class Question { #Id private String id; private String questionText; public Question( String questionText ) { this.questionText = questionText; } } QuestionRepository.java package com.example.quiz.repository; import com.example.quiz.model.Question; import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.stereotype.Repository; import java.util.List; #Repository public interface QuestionRepository extends MongoRepository<Question, String> { List<Question> findAll(); } QuizController.java package com.example.quiz.controller; import com.example.quiz.model.Question; import com.example.quiz.repository.QuestionRepository; import com.example.quiz.service.QuestionService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; #CrossOrigin(origins = "http://localhost:8081") #RestController public class QuestionController { #Autowired QuestionRepository questionRepository; #Autowired QuestionService questionService; #GetMapping("/question") public Question setQuestion(Question question) { return questionRepository.insert(new Question( question.getQuestionText() )); } #GetMapping("/all") public List<Question> getQuestion() { return questionService.getAllQuestions(); } #RequestMapping("/hello") public String hello() { return "Hello"; } } QuizService.java package com.example.quiz.service; import com.example.quiz.model.Question; import com.example.quiz.repository.QuestionRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; #Service public class QuestionService { #Autowired QuestionRepository questionRepository; public List<Question> getAllQuestions() { return questionRepository.findAll(); } } application.properties spring.data.mongodb.authentication-database=admin spring.data.mongodb.username=rootuser spring.data.mongodb.password=rootpass spring.data.mongodb.database=quizdatabase spring.data.mongodb.port=27017 spring.data.mongodb.host=localhost spring.data.mongodb.auto-index-creation=true server.error.include-message = always docker-compose.yaml version: "3.8" services: mongodb: image: mongo container_name: mongodb ports: - 27017:27017 volumes: - data:/data environment: - MONGO_INITDB_ROOT_USERNAME=rootuser - MONGO_INITDB_ROOT_PASSWORD=rootpass mongo-express: image: mongo-express container_name: mongo-express restart: always ports: - 8081:8081 environment: - ME_CONFIG_MONGODB_ADMINUSERNAME=rootuser - ME_CONFIG_MONGODB_ADMINPASSWORD=rootpass - ME_CONFIG_MONGODB_SERVER=mongodb volumes: data: {} networks: default: name: mongodb_network Logs 2021-08-15 18:42:56.878 INFO 99293 --- [ restartedMain] com.example.quiz.QuizApplication : Starting QuizApplication using Java 1.8.0_151 on Vishwajeets-MacBook-Pro-2.local with PID 99293 (/Users/vishwajeetkumar/Downloads/quiz3Test/target/classes started by vishwajeetkumar in /Users/vishwajeetkumar/Downloads/quiz3Test) 2021-08-15 18:42:56.898 INFO 99293 --- [ restartedMain] com.example.quiz.QuizApplication : No active profile set, falling back to default profiles: default 2021-08-15 18:42:57.641 INFO 99293 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable 2021-08-15 18:42:57.643 INFO 99293 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG' 2021-08-15 18:43:00.470 INFO 99293 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data MongoDB repositories in DEFAULT mode. 2021-08-15 18:43:00.546 INFO 99293 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 68 ms. Found 1 MongoDB repository interfaces. 2021-08-15 18:43:06.280 INFO 99293 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2021-08-15 18:43:06.411 INFO 99293 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2021-08-15 18:43:06.429 INFO 99293 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.50] 2021-08-15 18:43:07.227 INFO 99293 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2021-08-15 18:43:07.228 INFO 99293 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 9569 ms 2021-08-15 18:43:09.206 INFO 99293 --- [ restartedMain] org.mongodb.driver.cluster : Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms'} 2021-08-15 18:43:09.464 INFO 99293 --- [localhost:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:2, serverValue:70}] to localhost:27017 2021-08-15 18:43:09.464 INFO 99293 --- [localhost:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:1, serverValue:71}] to localhost:27017 2021-08-15 18:43:09.468 INFO 99293 --- [localhost:27017] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=13, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=93274206} 2021-08-15 18:43:10.444 INFO 99293 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729 2021-08-15 18:43:15.615 INFO 99293 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '' 2021-08-15 18:43:15.715 INFO 99293 --- [ restartedMain] com.example.quiz.QuizApplication : Started QuizApplication in 24.388 seconds (JVM running for 28.746)
Rest Controller not seem to work in my Springboot
I have a Springboot project I created by copying the libraries from mvn repository, not using SPRING INITLZR. Anyway Springboot main seems to be working fine. It's just that my Rest Controller is not displaying the message I want to. Main.class #SpringBootApplication public class MovieInfoServiceApplication { public static void main(String[] args) throws IOException, GeneralSecurityException, MessagingException { SpringApplication.run(MovieInfoServiceApplication.class, args); } } RestController.class #RestController #RequestMapping("/") public class MovieServiceRestController { #GetMapping("/hello") //#CrossOrigin(origins = "http://localhost:9005") public String hello() { return "movie-service-api: hello from MovieServiceRestController"; } } pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.4.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.backend</groupId> <artifactId>movie-info-service</artifactId> <version>0.0.1-SNAPSHOT</version> <name>movie-info-service</name> <description>microservices about movie info</description> <properties> <java.version>11</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web-services</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> This is what I got when I access "localhost:9005/hello" Springboot logs 2020-10-18 02:18:35.481 INFO 4347 --- [ main] com.gmailapijava.main.GmailAPIJavaMain : No active profile set, falling back to default profiles: default 2020-10-18 02:18:38.779 INFO 4347 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.ws.config.annotation.DelegatingWsConfiguration' of type [org.springframework.ws.config.annotation.DelegatingWsConfiguration$$EnhancerBySpringCGLIB$$e708c1d] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2020-10-18 02:18:39.142 INFO 4347 --- [ main] .w.s.a.s.AnnotationActionEndpointMapping : Supporting [WS-Addressing August 2004, WS-Addressing 1.0] 2020-10-18 02:18:40.286 INFO 4347 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9005 (http) 2020-10-18 02:18:40.307 INFO 4347 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2020-10-18 02:18:40.307 INFO 4347 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.38] 2020-10-18 02:18:41.175 INFO 4347 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2020-10-18 02:18:41.176 INFO 4347 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 5020 ms 2020-10-18 02:18:42.329 INFO 4347 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor' 2020-10-18 02:18:43.369 INFO 4347 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9005 (http) with context path '' 2020-10-18 02:18:43.391 INFO 4347 --- [ main] com.gmailapijava.main.GmailAPIJavaMain : Started GmailAPIJavaMain in 10.504 seconds (JVM running for 14.339) 2020-10-18 02:18:56.903 INFO 4347 --- [nio-9005-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet' 2020-10-18 02:18:56.905 INFO 4347 --- [nio-9005-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2020-10-18 02:18:56.919 INFO 4347 --- [nio-9005-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 14 ms
SpringApplication.run(GmailAPIJavaMain.class, args); should be SpringApplication.run(MovieInfoServiceApplication.class, args); Also check if the controller package is getting scanned.
Try it like this #RestController public class MovieServiceRestController { #GetMapping("/hello") //#CrossOrigin(origins = "http://localhost:9005") public String hello() { return "movie-service-api: hello from MovieServiceRestController"; } }
Rest controller not mapping in spring boot
My application runs but nothing about mapping is shown in console. My Application class file is above controller and also added #ComponentScan(basePackages : "com.org.name.controller") to scan for controllers. Still no mapping shows up in console. I have commented out #Autowired in controller class as i was getting error of : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2019-07-12 11:05:16.014 ERROR 14104 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Field userService in com.homzhub.lms.controller.UserController required a bean of type 'com.homzhub.lms.service.UserService' that could not be found. The injection point has the following annotations: - #org.springframework.beans.factory.annotation.Autowired(required=true) Action: Consider defining a bean of type 'com.homzhub.lms.service.UserService' in your configuration. Main class: package com.homzhub.lms; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; #SpringBootApplication #ComponentScan(basePackages = {"com.homzhub.lms.controller"}) //#EnableJpaRepositories("repository") //#EnableAutoConfiguration public class LmsApplication{ public static void main(String[] args){ SpringApplication.run(LmsApplication.class, args); } } appointment controller : package com.homzhub.lms.controller; import java.security.Principal; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import com.homzhub.lms.entity.Appointment; import com.homzhub.lms.entity.User; import com.homzhub.lms.service.AppointmentService; import com.homzhub.lms.service.UserService; #Controller #RequestMapping(path = "/appointment") public class AppointmentController { // #Autowired private AppointmentService appointmentService; //#Autowired private UserService userService; #RequestMapping(value = "/create", method = RequestMethod.GET) public void createAppointment(Model model) { Appointment appointment = new Appointment(); model.addAttribute("appointment", appointment); model.addAttribute("dateString", ""); } #RequestMapping(value = "/create", method = RequestMethod.POST) public String createAppointmentPost(#ModelAttribute("appointment") Appointment appointment, #ModelAttribute("dateString") String date, Model model, Principal principal) throws ParseException { SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd hh:mm"); Date d1 = format1.parse(date); appointment.setDate(d1); User user = userService.findByUsername(principal.getName()); appointment.setUser(user); appointmentService.createAppointment(appointment); return "redirect:/userFront"; } } pom.xml file : <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <!-- <version>1.5.21.RELEASE</version> --> <version>2.1.6.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <groupId>com.homzhub</groupId> <artifactId>lms</artifactId> <version>0.0.1-SNAPSHOT</version> <name>lms</name> <description>Lead Management System</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> </plugin> </plugins> </build> </project> Console output. After commenting out #Autowired in controller classes the application runs but no mapping is done : 2019-07-12 12:58:04.638 INFO 18828 --- [ main] com.homzhub.lms.LmsApplication : Starting LmsApplication v0.0.1-SNAPSHOT on rms-Lenovo-ideapad-330-15IKB with PID 18828 (/home/rms/lms/target/lms-0.0.1-SNAPSHOT.jar started by rms in /home/rms/lms) 2019-07-12 12:58:04.644 INFO 18828 --- [ main] com.homzhub.lms.LmsApplication : No active profile set, falling back to default profiles: default 2019-07-12 12:58:05.941 INFO 18828 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode. 2019-07-12 12:58:06.161 INFO 18828 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 204ms. Found 13 repository interfaces. 2019-07-12 12:58:06.849 INFO 18828 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$d931452d] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2019-07-12 12:58:07.301 INFO 18828 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2019-07-12 12:58:07.350 INFO 18828 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2019-07-12 12:58:07.350 INFO 18828 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.21] 2019-07-12 12:58:07.484 INFO 18828 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2019-07-12 12:58:07.484 INFO 18828 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2751 ms 2019-07-12 12:58:07.952 INFO 18828 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... 2019-07-12 12:58:08.286 INFO 18828 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed. 2019-07-12 12:58:08.388 INFO 18828 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [ name: default ...] 2019-07-12 12:58:08.519 INFO 18828 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.3.10.Final} 2019-07-12 12:58:08.521 INFO 18828 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found 2019-07-12 12:58:08.773 INFO 18828 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.4.Final} 2019-07-12 12:58:09.175 INFO 18828 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect 2019-07-12 12:58:10.967 INFO 18828 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default' 2019-07-12 12:58:12.284 INFO 18828 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor' 2019-07-12 12:58:12.364 WARN 18828 --- [ main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning 2019-07-12 12:58:12.923 INFO 18828 --- [ main] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page template: index 2019-07-12 12:58:13.211 INFO 18828 --- [ main] .s.s.UserDetailsServiceAutoConfiguration : Using generated security password: f1e93a8f-d01a-4050-8724-87ff348fab02 2019-07-12 12:58:13.388 INFO 18828 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#1dcca8d3, org.springframework.security.web.context.SecurityContextPersistenceFilter#6daf2337, org.springframework.security.web.header.HeaderWriterFilter#70e3f36f, org.springframework.security.web.csrf.CsrfFilter#3c7cfcbb, org.springframework.security.web.authentication.logout.LogoutFilter#7d755813, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#4e25147a, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter#60e5272, org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter#5631962, org.springframework.security.web.authentication.www.BasicAuthenticationFilter#56303475, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#250b236d, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#432034a, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#52a70627, org.springframework.security.web.session.SessionManagementFilter#23e44287, org.springframework.security.web.access.ExceptionTranslationFilter#1bfe3203, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#71870da7] 2019-07-12 12:58:13.517 INFO 18828 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '' 2019-07-12 12:58:13.520 INFO 18828 --- [ main] com.homzhub.lms.LmsApplication : Started LmsApplication in 9.518 seconds (JVM running for 10.158) UserService class : package com.homzhub.lms.service; import java.util.List; import java.util.Set; import org.springframework.stereotype.Service; import com.homzhub.lms.entity.User; import com.homzhub.lms.security.UserRole; //#Service("userDetailsService") #Service public interface UserService{ User findByUsername(String username); User findByEmail(String email); // User findByPhoneNumber(String phoneNumber); boolean checkUserExists(String username, String email); boolean checkUsernameExists(String username); boolean checkEmailExists(String email); void save(User user); User createUser(User user, Set<UserRole> userRoles); User saveUser(User user); List<User> findUserList(); void enableUser(String username); void disableUser(String username); }
If it isn't already, you need to define UserService as a Component, or more appropriately as a Service. If it already is you have to map it, which is a bit weird considering Spring should do that on its own.
Your are only scanning com.homzhub.lms.controller and UserService is not under ComponentScan. You need to add service package to ComponentScan #ComponentScan(basePackages = {"com.homzhub.lms"})
You service is under com.homzhub.lms.service package so you have to add this package to #ComponentScan too, so Spring will scan this package too and pick up the classes marked with stereotypes there : #SpringBootApplication #ComponentScan(basePackages = {"com.homzhub.lms.controller, "com.homzhub.lms.service"}) public class LmsApplication{ public static void main(String[] args){ SpringApplication.run(LmsApplication.class, args); } } However I can see that your class annotated with #SpringBootApplication is already above all the packages with your components so you could get rid of #ComponentScan annotation at all. So it will scan nested packages by default. And also remember about annotating your service classes with Spring stereotypes annotations for example #Service so component scan will be able to pick them up.
Uncomment #Autowired annotation. Put #Service annotation on the implementing class instead of the interface and make sure your implementing class is discover-able via componentScan. Also, as a side note, Spring will scan all subpackages of your main class (class with #SpringBootApplication annotation). So it would be a good idea to have a directory structure like com.homzhub.lms as a root and com.homzhub.lms.controller for controllers com.homzhub.lms.service for service and com.homzhub.lms.service.impl if you want to keep implementations in a different package. If you are following this structure, you won't need componentScan.
I am trying to stand up a Eureka Registry service, however, the Eureka server stops immediately after start
I am trying to stand up a spring cloud Eureka Server at my local machine by following instruction from Spring cloud website, however, the server was shutdown right after started, see below log files. Here is the log file: 2018-07-16 11:23:15.313 INFO 10792 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0 2018-07-16 11:23:15.320 INFO 10792 --- [ Thread-12] o.s.c.n.e.server.EurekaServerBootstrap : Setting the eureka configuration.. 2018-07-16 11:23:15.322 INFO 10792 --- [ Thread-12] o.s.c.n.e.server.EurekaServerBootstrap : Eureka data center value eureka.datacenter is not set, defaulting to default 2018-07-16 11:23:15.322 INFO 10792 --- [ Thread-12] o.s.c.n.e.server.EurekaServerBootstrap : Eureka environment value eureka.environment is not set, defaulting to test 2018-07-16 11:23:15.347 INFO 10792 --- [ Thread-12] o.s.c.n.e.server.EurekaServerBootstrap : isAws returned false 2018-07-16 11:23:15.349 INFO 10792 --- [ Thread-12] o.s.c.n.e.server.EurekaServerBootstrap : Initialized server context 2018-07-16 11:23:15.350 INFO 10792 --- [ Thread-12] c.n.e.r.PeerAwareInstanceRegistryImpl : Got 1 instances from neighboring DS node 2018-07-16 11:23:15.350 INFO 10792 --- [ Thread-12] c.n.e.r.PeerAwareInstanceRegistryImpl : Renew threshold is: 1 2018-07-16 11:23:15.351 INFO 10792 --- [ Thread-12] c.n.e.r.PeerAwareInstanceRegistryImpl : Changing status to UP 2018-07-16 11:23:15.399 INFO 10792 --- [ main] c.c.E.EurekaServiceApplicationTests : Started EurekaServiceApplicationTests in 10.859 seconds (JVM running for 13.307) 2018-07-16 11:23:15.435 INFO 10792 --- [ Thread-12] e.s.EurekaServerInitializerConfiguration : Started Eureka Server 2018-07-16 11:23:15.728 INFO 10792 --- [ Thread-13] o.s.w.c.s.GenericWebApplicationContext : Closing org.springframework.web.context.support.GenericWebApplicationContext#72209d93: startup date [Mon Jul 16 11:23:07 EDT 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext#6326d182 2018-07-16 11:23:15.735 INFO 10792 --- [ Thread-13] o.s.c.n.e.s.EurekaServiceRegistry : Unregistering application EurekaService with eureka with status DOWN 2018-07-16 11:23:15.740 INFO 10792 --- [ Thread-13] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 0 2018-07-16 11:23:15.743 INFO 10792 --- [ Thread-13] c.n.eureka.DefaultEurekaServerContext : Shutting down ... 2018-07-16 11:23:15.748 INFO 10792 --- [ Thread-13] c.n.eureka.DefaultEurekaServerContext : Shut down 2018-07-16 11:23:15.752 INFO 10792 --- [ Thread-13] com.netflix.discovery.DiscoveryClient : Shutting down DiscoveryClient ... 2018-07-16 11:23:15.752 INFO 10792 --- [ Thread-13] com.netflix.discovery.DiscoveryClient : Completed shut down of DiscoveryClient Here is the POM file: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.cyanne</groupId> <artifactId>EurekaService</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>EurekaService</name> <description>Eureka Service for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>10</java.version> <spring-cloud.version>Finchley.RELEASE</spring-cloud.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> Here is my class file: package com.cyanne.EurekaService; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; #SpringBootApplication #EnableEurekaServer public class EurekaServiceApplication { public static void main(String[] args) { SpringApplication.run(EurekaServiceApplication.class, args); } } Here is my application Property file: spring.application.name=EurekaService eureka.client.serviceUrl.defaultZone:http://localhost:9091/eureka/ server.port=9091 eureka.client.register-with-eureka=false eureka.client.fetch-registry=false