早就看到了这个框架,最近也使用了一下,感觉入手还是很容易的,先来个开胃菜,实现一个简单的WEB服务器,并且用到CDI;
(1)直接使用IDEA的插件创建maven项目;
(2)编写业务接口
1 2 3 |
public interface TestService { public String run(String name); } |
实现类
1 2 3 4 5 6 7 8 |
@ApplicationScoped @Service1 public class TestServiceimpl implements TestService { @Override public String run(String name) { return "业务1" + name; } } |
1 2 3 4 5 6 7 8 |
@ApplicationScoped @Service2 public class TestServiceimpl2 implements TestService { @Override public String run(String name) { return "业务2" + name; } } |
注解@Service1和@Service2,这里是用来@Inject注入时区分实现类的;
1 2 3 4 |
@Qualifier @Retention(RetentionPolicy.RUNTIME) public @interface Service1 { } |
(3)编写控制器资源:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
@Path("/") public class HelloResource { |
(4)然后就是利用maven直接启动测试,或者打包成native文件直接启动;
本文由 GY 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为:
2021/11/19 15:23