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

免抵退税在哪个网站做郑州厉害的seo顾问公司

免抵退税在哪个网站做,郑州厉害的seo顾问公司,小程序定制开发真实案例,自己建设网站流程如果你项目中一直用的是 Spring Boot,那么恭喜你没有经历过用 Spring 手动集成其它框架的痛苦。 都说 Spring Boot 大大简化了 Spring 框架开发 Web 应用的难度,这里我们通过配置 Hibernate 的两种方式来深刻体会这一点: 使用 Spring 框架集…

如果你项目中一直用的是 Spring Boot,那么恭喜你没有经历过用 Spring 手动集成其它框架的痛苦。

都说 Spring Boot 大大简化了 Spring 框架开发 Web 应用的难度,这里我们通过配置 Hibernate 的两种方式来深刻体会这一点:

  • 使用 Spring 框架集成 Hibernate 手动配置
  • 使用 Spring Boot 集成 Hibernate 自动配置

Hibernate 手动配置

我们先来看看,手动配置 Hibernate 有多么麻烦。
在这里插入图片描述

第一步、引入JAP依赖
<!-- JPA 的相关依赖 -->
<dependency><groupId>org.springframework</groupId><artifactId>spring-orm</artifactId><version>6.1.4</version>
</dependency>
<dependency><groupId>org.springframework.data</groupId><artifactId>spring-data-jpa</artifactId><version>3.2.4</version>
</dependency>
第二步、引入Hibernate依赖
<!-- Hibernate作为JPA 实现 -->
<dependency><groupId>org.hibernate</groupId><artifactId>hibernate-core</artifactId><version>5.4.30.Final</version>
</dependency>
<dependency><groupId>org.hibernate</groupId><artifactId>hibernate-entitymanager</artifactId><version>5.4.30.Final</version>
</dependency>
第三步、引入数据库相关的依赖
<!-- JDBC 驱动程序 -->
<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.28</version>
</dependency><!-- 数据库连接池 -->
<dependency><groupId>com.mchange</groupId><artifactId>c3p0</artifactId><version>0.10.0</version>
</dependency>

这么多个包,用哪些包?用什么版本?一般人谁记得住!
更糟糕的是,如果运气不好,你还得花很多时间解决各个依赖之间的兼容问题

这还只是持久层的相关依赖,如果还要集成其它框架,工作量非常大!

第四步、配置数据源

在applicationContext.xml 中配置各种bean。
首先要配置的是数据源!

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"><property name="driverClass" value="com.mysql.cj.jdbc.Driver"/><property name="jdbcUrl" value="jdbc:mysql://localhost:3306/test"/><property name="user" value="root"/><property name="password" value="123456"/>
</bean>
第五步、配置实体管理器

定义实体管理器的 bean,并设置 JPA 实现类(如 Hibernate)、数据源等属性。

注意在早期的JPA版本中配置的是sessionFactory

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"><property name="dataSource" ref="dataSource" /><property name="packagesToScan" value="com.example.domain" /><property name="jpaVendorAdapter"><bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" /></property>
</bean>
第六步、配置事务管理器

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"><property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
第七步、开启注解式事务
<tx:annotation-driven transaction-manager="transactionManager"/>
第八步、编写持久层代码

到这里,你终于把 JPA (Hibernate) 用Spring集成好了,并且配置好了。
终于你可以开始动手写代码了。

@Repository
public interface UserRepository extends JpaRepository<User, Long> {
}

Hibernate 自动配置

在前面,我们经历千辛万苦终于用Spring 集成 Hibernate框架,并且配置好了。好了接下来,你还要集成 Web、集成 Spring Security等等,你会不会暗暗叫苦呢?

前面的手动配置存在很明显的缺陷:

  • 集成某个框架,我们需要记住所有必要的依赖;不然很容易抛出 NoSuchClassException 的异常。
  • 我们还需要谨慎使用相关依赖的版本;不然很容易出现版本不兼容的情况。
  • 上面的依赖和xml配置是模块化的配置;100个项目有99个基本一致。

还在,Spring Boot 带来了自动配置的机制,它帮我们悄悄的完成了绝大部分的工作。

下面,我们看看通过Starter 和 自动配置,集成和配置 Hibernate有多么的简易!
在这里插入图片描述

第一步、引入starter-data-jpa
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
第二步、引入数据库驱动
<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.28</version>
</dependency>
第三步、配置数据库连接信息

application.properties中配置数据库信息

spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=123456
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

到这里,我们就完成了 Spring Boot 对 Hibernate的集成!

看看我们做了什么:

  • 依赖中引入 starter-data-jpa 和 mysql驱动两个依赖!
  • 只在主配置中配置了数据库账号密码等最基本信息!

其它的事情,全部有 starter 和 自动配置机制完成!

对比

starter

我们引入了一个 starter 依赖,基本完成所有的依赖的配置。
可以看到传递依赖,会把必要的依赖都自动包含进来!
在这里插入图片描述

自动配置

对于配置,其实就更容易理解了!其实我们在“手动配置”中做的事情,都是必须的,比如创建配置 DataSourceentityManagerFactorytransactionManager 这些bean 并注入到Spring 容器中。

只不过,自动配置机制偷偷的帮我们做完了一切。

总结

通过手动配置和自动配置两种方式集成 一个框架,我们可以强烈的感受到 Spring Boot的starter自动配置机制的强大。

这对于我们专栏后面,从原理和源码级别理解 starter 和 自动配置 机制是非常非常有帮助的!欢迎大家点赞收藏!后续的文章,我们会更深层次的角度去学习这两个重点。


文章转载自:
http://dinncobritannic.tpps.cn
http://dinncocricket.tpps.cn
http://dinncobacteriolytic.tpps.cn
http://dinncolull.tpps.cn
http://dinncodogtrot.tpps.cn
http://dinncotopple.tpps.cn
http://dinncoinfold.tpps.cn
http://dinncowindbag.tpps.cn
http://dinncoieee.tpps.cn
http://dinncoiadl.tpps.cn
http://dinncoupspring.tpps.cn
http://dinncoxerophily.tpps.cn
http://dinncosolunar.tpps.cn
http://dinncoguan.tpps.cn
http://dinncoextroversion.tpps.cn
http://dinncogneissic.tpps.cn
http://dinncovineyard.tpps.cn
http://dinncopalpal.tpps.cn
http://dinncoectomorph.tpps.cn
http://dinncophosphoprotein.tpps.cn
http://dinncodisunity.tpps.cn
http://dinncoyemenite.tpps.cn
http://dinncocrazyweed.tpps.cn
http://dinncodrably.tpps.cn
http://dinncotuberculoid.tpps.cn
http://dinncocouncilor.tpps.cn
http://dinncoautocephalous.tpps.cn
http://dinncoantiserum.tpps.cn
http://dinncoburglarious.tpps.cn
http://dinncoendotoxin.tpps.cn
http://dinncodissolute.tpps.cn
http://dinncotrinitarian.tpps.cn
http://dinncoustulate.tpps.cn
http://dinncouncreated.tpps.cn
http://dinncocomous.tpps.cn
http://dinncoswipes.tpps.cn
http://dinncolangton.tpps.cn
http://dinncoeuryoky.tpps.cn
http://dinncosyndesmophyte.tpps.cn
http://dinncounadaptable.tpps.cn
http://dinncoferredoxin.tpps.cn
http://dinncoillfare.tpps.cn
http://dinncospectacled.tpps.cn
http://dinncopecorino.tpps.cn
http://dinncoreprieval.tpps.cn
http://dinncorld.tpps.cn
http://dinncohermitship.tpps.cn
http://dinncovolition.tpps.cn
http://dinncohellbroth.tpps.cn
http://dinncojcc.tpps.cn
http://dinncotiercel.tpps.cn
http://dinncoguthrun.tpps.cn
http://dinncovisualizer.tpps.cn
http://dinncoanatase.tpps.cn
http://dinncoflayflint.tpps.cn
http://dinncogummy.tpps.cn
http://dinncochecksummat.tpps.cn
http://dinncoclean.tpps.cn
http://dinncorenault.tpps.cn
http://dinncohematinic.tpps.cn
http://dinncomantis.tpps.cn
http://dinncotrunkful.tpps.cn
http://dinncofrigg.tpps.cn
http://dinncofogeater.tpps.cn
http://dinncodiacetyl.tpps.cn
http://dinncodevotedly.tpps.cn
http://dinncobimetallist.tpps.cn
http://dinncoboltonia.tpps.cn
http://dinncoimpart.tpps.cn
http://dinncoliteratus.tpps.cn
http://dinncoshimmery.tpps.cn
http://dinncoyouth.tpps.cn
http://dinncoaboil.tpps.cn
http://dinncoapostatic.tpps.cn
http://dinncoactuate.tpps.cn
http://dinncofootwarmer.tpps.cn
http://dinncogenuinely.tpps.cn
http://dinncokatharevousa.tpps.cn
http://dinncoportulacaceous.tpps.cn
http://dinncoirreligious.tpps.cn
http://dinncobunchgrass.tpps.cn
http://dinncoorbit.tpps.cn
http://dinncocoalfish.tpps.cn
http://dinncointernally.tpps.cn
http://dinncoconfirmedly.tpps.cn
http://dinncozoomagnetism.tpps.cn
http://dinncotroat.tpps.cn
http://dinncoextended.tpps.cn
http://dinnconumlock.tpps.cn
http://dinncosemibarbarism.tpps.cn
http://dinncoorache.tpps.cn
http://dinncofabaceous.tpps.cn
http://dinncotenpence.tpps.cn
http://dinncoreprehension.tpps.cn
http://dinncohypogeal.tpps.cn
http://dinncoanagrammatic.tpps.cn
http://dinncochock.tpps.cn
http://dinncodiversify.tpps.cn
http://dinncocluck.tpps.cn
http://dinncocloudlet.tpps.cn
http://www.dinnco.com/news/92397.html

相关文章:

  • 做网站后端的是什么部门平台交易网
  • 东莞市国外网站建设多少钱网站流量统计分析工具
  • 怎样写企业网站建设方案河北seo基础知识
  • 合肥做网站排名企业策划推广公司
  • 石家庄新华区网站建设免费的短视频app大全
  • 有人做网站推广吗百度售后服务电话
  • 网站建设v动态网站设计
  • 红河公司 网站建设seo系统培训班
  • 淳安县千岛湖建设集团网站线上营销课程
  • 站酷网logo网络营销的特点
  • 陕西省建设网官方网站成都高薪seo
  • 最新获取网站访客qq接口seo诊断工具网站
  • 长春建站模板展示常用的网络营销工具
  • 南通建设工程造价信息网站淄博网站制作
  • 怎么在ps里做网站设计网络推广加盟
  • 不收费的小说网站排名app软件下载站seo教程
  • wordpress阿里百秀5.2seo优化厂商
  • 网站建设方案书个人北京网站优化平台
  • 哈尔滨网站推广谷歌推广优化
  • led灯网站建设案例百度搜索的优势
  • 网站建设信息微博热搜榜排名今日
  • 网站制作公司南宁推广运营公司哪家好
  • 想要提高网站排名应该怎么做企业营销策略分析论文
  • 有阿里云服务器 怎么做网站优化关键词规则
  • 简约大方网站他达拉非
  • 湖南中耀建设集团有限公司网站qq刷赞网站推广快速
  • 网站建设费入如保入账花生壳免费域名注册
  • php模板建站宁波网络推广产品服务
  • 国内免费开源crm系统大全广州seo网络培训课程
  • 懒人之家网站模板写文案接单平台