当前位置: 首页 > news >正文

网站设计制作的服务怎么样网站文件夹结构

网站设计制作的服务怎么样,网站文件夹结构,网站建设改版,深圳微信网站在构建可扩展#xff0c;可靠的分布式系统的背景下#xff0c;“模块化”和“微服务体系结构”这两个术语如今经常出现。 众所周知#xff0c;Java平台本身在模块化方面很弱#xff08; Java 9将通过交付Jigsaw项目来解决这一问题#xff09;#xff0c;从而为OSGi和JBos… 在构建可扩展可靠的分布式系统的背景下“模块化”和“微服务体系结构”这两个术语如今经常出现。 众所周知Java平台本身在模块化方面很弱 Java 9将通过交付Jigsaw项目来解决这一问题从而为OSGi和JBoss Modules等框架的出现提供了机会。 当我在2007年第一次听说OSGi时 我真的很高兴Java应用程序可以基于OSGi的所有优点而受益。 但是很快就产生了挫败感而不是兴奋感没有工具支持兼容的库和框架非常有限非常不稳定很难对运行时进行故障排除。 显然普通的Java开发人员还没有准备好使用它因此我不得不把它放在架子上。 多年来 OSGi已经成熟很多并得到了广泛的社区支持。 好奇的读者可能会问特别是使用模块和OSGi有什么好处 仅举几个问题它有助于解决 显式和版本控制依赖关系管理模块声明所需的内容以及版本范围 占用空间小模块未包装所有依赖项 易于发布模块可以独立开发和发布 热重新部署可以重新部署各个模块而不会影响其他模块 在今天的帖子中我们将对使用OSGi构建模块化Java应用程序的最新技术水平进行10000英尺的考察。 撇开OSGi的好坏进行讨论我们将构建一个包含以下模块的示例应用程序 数据访问模块 商业服务模块 REST服务模块 用于数据访问的Apache OpenJPA 2.3.0 / JPA 2.0 不幸的是我们选择的OSGi实现尚未支持JPA 2.1 用于REST层的Apache CXF 3.0.1 / JAX-RS 2.0是应用程序的两个主要构建块。 我发现Christian Schneider的博客Liquid Liquidity是有关OSGi 以及许多其他主题的宝贵信息来源。 在OSGi世界中模块称为bundles 。 捆绑包显示了它们的依赖关系导入包和它们公开的包导出包因此其他捆绑包可以使用它们。 Apache Maven也支持此打包模型。 捆绑包由OSGi运行时或容器管理在我们的情况下将是Apache Karaf 3.0.1 实际上这是我们需要下载 和解压缩的内容。 让我停止说话更好地显示一些代码。 我们将从顶部 REST 开始一直到底部数据访问因为它更容易遵循。 我们的PeopleRestService是JAX-RS 2.0服务实现的典型示例 package com.example.jaxrs;import java.util.Collection;import javax.ws.rs.DELETE; import javax.ws.rs.DefaultValue; import javax.ws.rs.FormParam; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo;import com.example.data.model.Person; import com.example.services.PeopleService;Path( /people ) public class PeopleRestService {private PeopleService peopleService;Produces( { MediaType.APPLICATION_JSON } )GETpublic Collection Person getPeople( QueryParam( page) DefaultValue( 1 ) final int page ) {return peopleService.getPeople( page, 5 );}Produces( { MediaType.APPLICATION_JSON } )Path( /{email} )GETpublic Person getPerson( PathParam( email ) final String email ) {return peopleService.getByEmail( email );}Produces( { MediaType.APPLICATION_JSON } )POSTpublic Response addPerson( Context final UriInfo uriInfo,FormParam( email ) final String email, FormParam( firstName ) final String firstName, FormParam( lastName ) final String lastName ) {peopleService.addPerson( email, firstName, lastName );return Response.created( uriInfo.getRequestUriBuilder().path( email ).build() ).build();}Produces( { MediaType.APPLICATION_JSON } )Path( /{email} )PUTpublic Person updatePerson( PathParam( email ) final String email, FormParam( firstName ) final String firstName, FormParam( lastName ) final String lastName ) {final Person person peopleService.getByEmail( email );if( firstName ! null ) {person.setFirstName( firstName );}if( lastName ! null ) {person.setLastName( lastName );}return person; }Path( /{email} )DELETEpublic Response deletePerson( PathParam( email ) final String email ) {peopleService.removePerson( email );return Response.ok().build();}public void setPeopleService( final PeopleService peopleService ) {this.peopleService peopleService;} } 我们可以看到这里没有任何关于OSGi的信息 。 唯一的依赖是在某种程度上应该被注入PeopleRestService的PeopleService。 怎么样 通常 OSGi应用程序使用蓝图作为依赖项注入框架这与旧伙伴基于XML的Spring配置非常相似。 它应该与应用程序一起打包在OSGI-INF / blueprint文件夹中。 这是基于Apache CXF 3.0.1构建的REST模块的蓝图示例 blueprint xmlnshttp://www.osgi.org/xmlns/blueprint/v1.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:jaxrshttp://cxf.apache.org/blueprint/jaxrsxmlns:cxfhttp://cxf.apache.org/blueprint/corexsi:schemaLocationhttp://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsdhttp://cxf.apache.org/blueprint/jaxws http://cxf.apache.org/schemas/blueprint/jaxws.xsdhttp://cxf.apache.org/blueprint/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsdhttp://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsdcxf:bus idbuscxf:featurescxf:logging//cxf:features /cxf:busjaxrs:server address/api idapijaxrs:serviceBeansref component-idpeopleRestService//jaxrs:serviceBeansjaxrs:providersbean classcom.fasterxml.jackson.jaxrs.json.JacksonJsonProvider //jaxrs:providers/jaxrs:server!-- Implementation of the rest service --bean idpeopleRestService classcom.example.jaxrs.PeopleRestServiceproperty namepeopleService refpeopleService//bean reference idpeopleService interfacecom.example.services.PeopleService / /blueprint 非常小而简单基本上配置仅指出为了使模块正常工作应该提供对com.example.services.PeopleService的引用有效地由OSGi容器提供。 为了了解它将如何发生让我们看一下另一个公开服务的模块。 它仅包含一个接口PeopleService package com.example.services;import java.util.Collection;import com.example.data.model.Person;public interface PeopleService {Collection Person getPeople( int page, int pageSize );Person getByEmail( final String email );Person addPerson( final String email, final String firstName, final String lastName );void removePerson( final String email ); } 并提供其实现作为PeopleServiceImpl类 package com.example.services.impl;import java.util.Collection;import org.osgi.service.log.LogService;import com.example.data.PeopleDao; import com.example.data.model.Person; import com.example.services.PeopleService;public class PeopleServiceImpl implements PeopleService {private PeopleDao peopleDao;private LogService logService;Overridepublic Collection Person getPeople( final int page, final int pageSize ) { logService.log( LogService.LOG_INFO, Getting all people );return peopleDao.findAll( page, pageSize );}Overridepublic Person getByEmail( final String email ) {logService.log( LogService.LOG_INFO, Looking for a person with e-mail: email );return peopleDao.find( email ); }Overridepublic Person addPerson( final String email, final String firstName, final String lastName ) {logService.log( LogService.LOG_INFO, Adding new person with e-mail: email );return peopleDao.save( new Person( email, firstName, lastName ) );}Overridepublic void removePerson( final String email ) {logService.log( LogService.LOG_INFO, Removing a person with e-mail: email );peopleDao.delete( email );}public void setPeopleDao( final PeopleDao peopleDao ) {this.peopleDao peopleDao;}public void setLogService( final LogService logService ) {this.logService logService;} } 这次又一次是非常小的干净的实现它具有两个可注入的依赖项org.osgi.service.log.LogService和com.example.data.PeopleDao 。 它的蓝图配置位于OSGI-INF / blueprint文件夹中看起来也很紧凑 blueprint xmlnshttp://www.osgi.org/xmlns/blueprint/v1.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xsi:schemaLocationhttp://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsdservice refpeopleService interfacecom.example.services.PeopleService / bean idpeopleService classcom.example.services.impl.PeopleServiceImplproperty namepeopleDao refpeopleDao / property namelogService reflogService //beanreference idpeopleDao interfacecom.example.data.PeopleDao /reference idlogService interfaceorg.osgi.service.log.LogService / /blueprint 预期由OSGi容器在运行时提供对PeopleDao和LogService的引用。 但是 PeopleService的实现是作为服务公开的一旦其捆绑包被激活 OSGi容器将能够将其注入PeopleRestService 。 难题的最后一部分是数据访问模块它稍微复杂一些它包含持久性配置 META-INF / persistence.xml 并且基本上依赖于OSGi容器的JPA 2.0功能。 persistence.xml非常基本 persistence xmlnshttp://java.sun.com/xml/ns/persistencexmlns:xsihttp://www.w3.org/2001/XMLSchema-instanceversion2.0persistence-unit namepeopleDb transaction-typeJTAjta-data-sourceosgi:service/javax.sql.DataSource/(osgi.jndi.service.namepeopleDb)/jta-data-source classcom.example.data.model.Person/classpropertiesproperty nameopenjpa.jdbc.SynchronizeMappings valuebuildSchema/ /properties /persistence-unit /persistence 与服务模块类似还有一个PeopleDao公开的接口 package com.example.data;import java.util.Collection;import com.example.data.model.Person;public interface PeopleDao {Person save( final Person person );Person find( final String email );Collection Person findAll( final int page, final int pageSize );void delete( final String email ); } 通过其实现PeopleDaoImpl package com.example.data.impl;import java.util.Collection;import javax.persistence.EntityManager; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery;import com.example.data.PeopleDao; import com.example.data.model.Person;public class PeopleDaoImpl implements PeopleDao {private EntityManager entityManager;Overridepublic Person save( final Person person ) {entityManager.persist( person );return person;}Overridepublic Person find( final String email ) {return entityManager.find( Person.class, email );}public void setEntityManager( final EntityManager entityManager ) {this.entityManager entityManager;}Overridepublic Collection Person findAll( final int page, final int pageSize ) {final CriteriaBuilder cb entityManager.getCriteriaBuilder();final CriteriaQuery Person query cb.createQuery( Person.class );query.from( Person.class );return entityManager.createQuery( query ).setFirstResult(( page - 1 ) * pageSize ).setMaxResults( pageSize ) .getResultList();}Overridepublic void delete( final String email ) {entityManager.remove( find( email ) );} } 请注意尽管我们正在执行数据操作但是没有提及事务也没有对实体管理器的事务API的显式调用。 我们将使用声明式方法进行事务处理因为蓝图配置支持位置不变 OSGI-INF / blueprint文件夹 blueprint xmlnshttp://www.osgi.org/xmlns/blueprint/v1.0.0 xmlns:jpahttp://aries.apache.org/xmlns/jpa/v1.1.0xmlns:txhttp://aries.apache.org/xmlns/transactions/v1.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xsi:schemaLocationhttp://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsdservice refpeopleDao interfacecom.example.data.PeopleDao /bean idpeopleDao classcom.example.data.impl.PeopleDaoImpljpa:context unitnamepeopleDb propertyentityManager /tx:transaction method* valueRequired//beanbean iddataSource classorg.hsqldb.jdbc.JDBCDataSourceproperty nameurl valuejdbc:hsqldb:mem:peopleDb//beanservice refdataSource interfacejavax.sql.DataSource service-properties entry keyosgi.jndi.service.name valuepeopleDb / /service-properties /service /blueprint 要记住的一件事应用程序不需要创建JPA 2.1的实体管理器 OSGi运行时能够做到这一点并将其注入到需要的地方由jpacontext声明驱动。 因此 txtransaction指示运行时将选定的服务方法包装在事务内。 现在当提供最后一个服务PeopleDao时 我们准备使用Apache Karaf 3.0.1部署我们的模块。 三个步骤很容易做到 运行Apache Karaf 3.0.1容器 bin/karaf (or bin\karaf.bat on Windows) 从Apache Karaf 3.0.1 shell执行以下命令 feature:repo-add cxf 3.0.1 feature:install http cxf jpa openjpa transaction jndi jdbc install -s mvn:org.hsqldb/hsqldb/2.3.2 install -s mvn:com.fasterxml.jackson.core/jackson-core/2.4.0 install -s mvn:com.fasterxml.jackson.core/jackson-annotations/2.4.0 install -s mvn:com.fasterxml.jackson.core/jackson-databind/2.4.0 install -s mvn:com.fasterxml.jackson.jaxrs/jackson-jaxrs-base/2.4.0 install -s mvn:com.fasterxml.jackson.jaxrs/jackson-jaxrs-json-provider/2.4.0 构建我们的模块并将其复制到Apache Karaf 3.0.1的deploy文件夹中容器仍在运行时 mvn clean package cp module*/target/*jar apache-karaf-3.0.1/deploy/ 在Apache Karaf 3.0.1 Shell中运行list命令时应该看到所有激活的捆绑软件模块的列表类似于此列表 其中module-service module-jax-rs和module-data对应于我们正在开发的模块。 默认情况下我们所有的Apache CXF 3.0.1服务将在基本URL http// 8181 / cxf / api /上提供。 通过在Apache Karaf 3.0.1 shell中执行cxflist-endpoints -f命令很容易检查。 让我们通过发送几个HTTP请求来确保REST层按预期工作。 让我们创建一个新人 curl http://localhost:8181/cxf/api/people -iX POST -d firstNameTomlastNameKnockeremailab.comHTTP/1.1 201 Created Content-Length: 0 Date: Sat, 09 Aug 2014 15:26:17 GMT Location: http://localhost:8181/cxf/api/people/ab.com Server: Jetty(8.1.14.v20131031) 并确认该人已成功创建 curl -i http://localhost:8181/cxf/api/peopleHTTP/1.1 200 OK Content-Type: application/json Date: Sat, 09 Aug 2014 15:28:20 GMT Transfer-Encoding: chunked Server: Jetty(8.1.14.v20131031)[{email:ab.com,firstName:Tom,lastName:Knocker}] 还要很好地检查数据库是否有人填充。 使用Apache Karaf 3.0.1 shell只需执行两个命令即可轻松完成 jdbcdatasources和jdbcquery peopleDb“ select * from people” 。 太棒了 我希望这篇介绍性很强的博客文章能打开您可以用来开发健壮可扩展模块化和可管理的软件的另一项有趣的技术。 我们没有涉及很多东西但是您可以在这里找到它们。 完整的源代码可在GitHub上获得 。 Hibernate 4.2.x / 4.3.x用户注意不幸的是在当前版本的Apache Karaf 3.0.1中 Hibernate 4.3.x完全可以正常工作因为尚不支持JPA 2.1 但是我设法做到了与Hibernate 4.2.x一起运行时容器通常拒绝解析与JPA相关的依赖关系。 翻译自: https://www.javacodegeeks.com/2014/08/osgi-the-gateway-into-micro-services-architecture.html
http://wiki.neutronadmin.com/news/280310/

相关文章:

  • 怎样建设企业网站做网站十大公司哪家好
  • 电子请柬网站开发竞赛作品发表网站怎么做
  • 淄博网站建设公司有几家深圳公共交易资源平台
  • 注销建设工程规划许可证在哪个网站百度推广一个月多少钱
  • 建立网站心得自己怎么做网站建设
  • 莱州网站建设方案广告公司名称创意
  • 网站登记备案查询网站建设人员工资
  • 菏砖网站建设网站建设费进什么科目
  • 广西建设监理协会官网站wordpress禁用媒体库
  • 网站工程师简历专业返利网站建设
  • 招聘网站是做什麼的hao123网址下载到桌面
  • oracle 网站开发有限公司和公司哪个好
  • 凤岗网站建设西安seo工作室
  • 网站续费会计分录怎样做网站模板和定制的区别
  • 成都网站建设索q479185700内容营销的4个主要方式
  • 扁平化网站下载网络版微信
  • 广州开发区投资集团有限公司海外广告优化师
  • dw5怎样做网站建网站要花多少钱
  • 上海网站建设 普送wordpress主题模板下载
  • 快设计网站官网物流网站建设费用
  • 安徽海鹏建设工程有限公司网站精品建站
  • 石家庄做网站价格台州建设局网站信息价
  • 大良网站建设价位谷歌网站
  • 网站建设分金手指专业十时事新闻热点摘抄
  • 2021年十大购物网站排名自己开个网站
  • 网站系统运行环境网站建设前端需要看什么书
  • 电商网站开发参考文献织梦可以做英文网站吗
  • 驾校网站建设费用建设银行官方个人网站
  • ui怎样做网站pc版网站生成App
  • 福建建设执业资格注册管理中心网站外贸需要网站做生产车间展示