groovy dependencies { implementation 'osgi.enroute:enroute.base.api:1.0.0' implementation 'osgi.enroute:enroute.rest.api:1.0.0' compile 'org.webjars:angularjs:1.8.2' compile 'org.webjars:angular-ui-router:0.3.1' } package com.example.myapp.api; public interface MessageService { String getMessage(); } package com.example.myapp.impl; import com.example.myapp.api.MessageService; public class MessageServiceImpl implements MessageService { @Override public String getMessage() { return "Hello from OSGi!"; } } typescript import { Component, OnInit } from '@angular/core'; import { Http } from '@angular/http'; @Component({ selector: 'app-message', template: '<div>{{ message }}</div>' }) export class MessageComponent implements OnInit { public message: string; constructor(private http: Http) {} ngOnInit() { this.http.get('/api/message') .subscribe(response => this.message = response.json()); } } package com.example.myapp.rest; import com.example.myapp.api.MessageService; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; @Component(service = MessageResource.class) @Path("/api/message") public class MessageResource { @Reference private MessageService messageService; @GET @Produces(MediaType.APPLICATION_JSON) public String getMessage() { return "{ \"message\": \"" + messageService.getMessage() + "\" }"; } }


上一篇:
下一篇:
切换中文