2016-03-17 16:26:55.846 INFO 15020 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_UNKNOWN/WCABJ185046-368.corp.ncr.com:myapp:8085: registering service...
2016-03-17 16:26:55.942 INFO 15020 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_UNKNOWN/WCABJ185046-368.corp.ncr.com:myapp:8085 - registration status: 204
TestAppSpringBoot.java
@EnableDiscoveryClient
@SpringBootApplication
@ImportResource("classpath:main-config.xml")
public class TestAppSpringBoot extends SpringBootServletInitializer {
// I have to write commented code below to force eureka instance to set appname
// @Value("${spring.application.name:myapp}")
// private String appname;
// @Autowired
// private EurekaInstanceConfigBean eureka;
//
// @PostConstruct
// public void myPostConstruct(){
// eureka.setAppname(appname);
// System.setProperty("spring.application.name", appname);
// }
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(TestAppSpringBoot.class);
}
public static void main(String[] args) throws Exception {
SpringApplication app = new SpringApplication(TestAppSpringBoot.class);
app.run(args);
}
@Bean
public MessageDispatcherServlet messageDispatcherServlet() {
MessageDispatcherServlet mds = new MessageDispatcherServlet();
return mds;
}
@Bean
public ServletRegistrationBean messageDispatcherServletRegistration() {
ServletRegistrationBean registration = new ServletRegistrationBean(messageDispatcherServlet());
registration.setLoadOnStartup(1);
registration.addUrlMappings("/hello/*");
return registration;
}
}
This register in eureka service by name of UNKNOWN
bootstrap.yml
spring:
application:
name: myapp
server:
port: 8085
context-path: /AppStart
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
Now if I comment @ImportResource("classpath:main-config.xml"), then EurekaInstanceConfigBean.java picks up the appname from bootstrap.yml
@Value("${spring.application.name:unknown}")
private String appname = "unknown";
Comment From: birinderjagdev
UPDATE
I updated the pom file to have latest version (1.1.0.M5) for spring-cloud-netflix. Now I am getting following message also :
com.netflix.discovery.DiscoveryClient : Application name is not defined (defaults to UNKNOWN); registration not allowed
UPDATE 2
Adding following in bootstrap.yml resolved the issue:
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
instance:
health-check-url: http://localhost:8085
appname: my-app-name