This repository has been archived on 2022-07-05. You can view files and clone it, but cannot push or open issues/pull-requests.
steleks_backend/events/src/main/java/ba/steleks/EventsApplication.java

68 lines
2.0 KiB
Java

package ba.steleks;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@EnableDiscoveryClient
@SpringBootApplication
public class EventsApplication {
public static void main(String[] args) {
SpringApplication.run(EventsApplication.class, args);
}
}
@RefreshScope
@RestController
class MessageRestController {
@Value("${message:Hello default}")
private String message;
@Value("${user.password}")
private String password;
@RequestMapping("/message")
String getMessage() {
return this.message;
}
//@RequestMapping(path ="/temp", value = "/{id}", method = RequestMethod.GET)
//String getTemp(@PathVariable("id") Long id){
// return "temp " + Long.toString(id);
//}
@RequestMapping(value = "/whoami/{username}", method = RequestMethod.GET)
public String whoami(@PathVariable("username") String username) {
return String.format("Hello! You're %s and you'll become a(n) root, " +
"but only if your password is '%s'!\n",
username, password);
}
}
@RestController
class ServiceInstanceRestController {
@Autowired
private DiscoveryClient discoveryClient;
@RequestMapping("/service-instances/{applicationName}")
public List<ServiceInstance> serviceInstancesByApplicationName(
@PathVariable String applicationName) {
return this.discoveryClient.getInstances(applicationName);
}
}