先从persistence.xml开始:

<?xml version=”1.0″ encoding=”UTF-8″?>
<persistence version=”2.1″ xmlns=”http://java.sun.com/xml/ns/persistence” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_1.xsd”>
<persistence-unit name=”mysqldb”>
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>

<property name=”hibernate.dialect” value=”org.hibernate.dialect.MySQL5Dialect” />
<property name=”hibernate.connection.driver_class” value=”com.mysql.jdbc.Driver” />
<property name=”hibernate.connection.username” value=”root” />
<property name=”hibernate.connection.password” value=”123456″ />
<property name=”hibernate.connection.url” value=”jdbc:mysql://localhost:3306/twq?useUnicode=true&amp;characterEncoding=UTF-8″ />

<!–设置外连接抓取树的最大深度 –>
<property name=”hibernate.max_fetch_depth” value=”3″ />
<!–自动输出schema创建DDL语句 –>
<property name=”hibernate.hbm2ddl.auto” value=”update” />
<!– <property name=”hibernate.show_sql” value=”true” />
<property name=”hibernate.format_sql” value=”true” /> –>
<property name=”javax.persistence.validation.mode” value=”none”/>
</properties>
</persistence-unit>
<persistence-unit name=”sqlserverdb”>
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>

<property name=”hibernate.dialect” value=”org.hibernate.dialect.SQLServerDialect” />
<property name=”hibernate.connection.driver_class” value=”com.microsoft.sqlserver.jdbc.SQLServerDriver” />
<property name=”hibernate.connection.username” value=”sa” />
<property name=”hibernate.connection.password” value=”123abc” />
<property name=”hibernate.connection.url” value=”jdbc:sqlserver://192.168.130.10:1433;DatabaseName=unionman” />

<!–设置外连接抓取树的最大深度 –>
<property name=”hibernate.max_fetch_depth” value=”3″ />
<!–自动输出schema创建DDL语句
<property name=”hibernate.hbm2ddl.auto” value=”update” /> –>
<!– <property name=”hibernate.show_sql” value=”true” />
<property name=”hibernate.format_sql” value=”true” /> –>
<property name=”javax.persistence.validation.mode” value=”none”/>
</properties>
</persistence-unit>
</persistence>

这里定义两个:<persistence-unit>  注意name值区分。

2.applicationContext.xml:

<?xml version=”1.0″ encoding=”UTF-8″?>
<beans xmlns=”http://www.springframework.org/schema/beans”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xmlns:aop=”http://www.springframework.org/schema/aop”
xmlns:context=”http://www.springframework.org/schema/context”
xmlns:jpa=”http://www.springframework.org/schema/data/jpa”
xmlns:mvc=”http://www.springframework.org/schema/mvc”
xmlns:tx=”http://www.springframework.org/schema/tx”
xmlns:util=”http://www.springframework.org/schema/util”
xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.2.xsd”>

<context:annotation-config/>
<context:component-scan base-package=”com.tw”/>
<bean id=”defaultPersistenceUnitManager” class=”org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager”>
<property name=”persistenceXmlLocation” value=”classpath:META-INF/persistence.xml”/>
<!– comment dataSourceLooup to use jndi –>
<property name=”dataSourceLookup”>
<bean class=”org.springframework.jdbc.datasource.lookup.BeanFactoryDataSourceLookup” />
</property>
</bean>

<!– 整合mysqljpa –>
<bean id=”mysqlEntityManagerFactory” class=”org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean”>
<property name=”persistenceUnitManager” ref=”defaultPersistenceUnitManager”></property>
<property name=”persistenceUnitName” value=”mysqldb”></property>
<property name=”jpaVendorAdapter”>
<bean class=”org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter”>
<property name=”showSql” value=”true”></property>
<property name=”database” value=”MYSQL”></property>
</bean>
</property>
</bean>
<bean id=”mysqltransactionManager” class=”org.springframework.orm.jpa.JpaTransactionManager”>
<property name=”entityManagerFactory” ref=”mysqlEntityManagerFactory” />
<qualifier value=”mysqlEM”/>
</bean>
<tx:annotation-driven transaction-manager=”mysqltransactionManager” proxy-target-class=”false”/>

<!– 整合sqlserverjpa –>
<bean id=”sqlserverEntityManagerFactory” class=”org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean”>
<property name=”persistenceUnitManager” ref=”defaultPersistenceUnitManager”></property>
<property name=”persistenceUnitName” value=”sqlserverdb”></property>
<property name=”jpaVendorAdapter”>
<bean class=”org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter”>
<property name=”showSql” value=”true”></property>
<property name=”database” value=”SQL_SERVER”></property>
</bean>
</property>
</bean>
<bean id=”sqlservertransactionManager” class=”org.springframework.orm.jpa.JpaTransactionManager”>
<property name=”entityManagerFactory” ref=”sqlserverEntityManagerFactory” />
<qualifier value=”sqlserverEM”/>
</bean>
<tx:annotation-driven transaction-manager=”sqlservertransactionManager” proxy-target-class=”false”/>

</beans>

注意我标注为红色的地方。

3.tw-servlet.xml:

<?xml version=”1.0″ encoding=”UTF-8″?>
<beans xmlns=”http://www.springframework.org/schema/beans”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:context=”http://www.springframework.org/schema/context”
xmlns:mvc=”http://www.springframework.org/schema/mvc”
xsi:schemaLocation=”http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd”>
<context:component-scan base-package=”com.tw.controller” />

<!– 避免IE执行AJAX时,返回JSON出现下载文件 –>
<bean id=”fastJsonHttpMessageConverter”
class=”com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter”>
<property name=”supportedMediaTypes”>
<list>
<value>application/json</value>
</list>
</property>
</bean>

<!– 启动Spring MVC的注解功能,完成请求和注解POJO的映射 –>
<bean
class=”org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter”>
<property name=”messageConverters”>
<list>
<ref bean=”fastJsonHttpMessageConverter” />
</list>
</property>
</bean>
<!– 对模型视图名称的解析,即在模型视图名称添加前后缀 –>
<bean
class=”org.springframework.web.servlet.view.InternalResourceViewResolver”>
<property name=”viewClass”
value=”org.springframework.web.servlet.view.JstlView” />
<property name=”prefix” value=”/”></property>
<property name=”suffix” value=”.jsp”></property>
</bean>

<!– 支持上传文件 –>
<bean id=”multipartResolver” class=”org.springframework.web.multipart.commons.CommonsMultipartResolver”/>

<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path=”/**”/>
<bean class=”com.tw.interceptor.PermissionAnnotationInterceptor”>
<property name=”excludeUrls”>
<list>
<value>/menu/init</value>
<value>/menu/tree</value>
<value>/user/login</value>
<value>/user/logout</value>
<value>/user/add</value>
</list>
</property>
</bean>
</mvc:interceptor>
</mvc:interceptors>
</beans>

这个没什么解释的。

4.web.xml:

<?xml version=”1.0″ encoding=”UTF-8″?>
<web-app xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns=”http://java.sun.com/xml/ns/javaee” xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd” id=”WebApp_ID” version=”3.0″>
<display-name>twc</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!– <filter>
<filter-name>OpenEntityManagerInViewFilter</filter-name>
<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
<init-param>
<param-name>entityManagerFactoryBeanName</param-name>
<param-value>entityManagerFactory</param-value>
</init-param>
<init-param>
<param-name>persistenceUnitName</param-name>
<param-value>tw</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>OpenEntityManagerInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> –>
<servlet>
<servlet-name>tw</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:tw-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>tw</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.json</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.gif</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.png</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.ico</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.doc</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.xls</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.docx</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.xlsx</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.txt</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.swf</url-pattern>
</servlet-mapping>
<filter>
<filter-name>Spring character encoding filter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Spring character encoding filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

看到我在web.xml中标注的红色没有,如果你想用多数据源就把这个干掉,也就是说hibernate的延迟加载功能就不要用了。

其实在项目中最好不要用延迟加载,你懂的。

配置基本完成。

下面是代码了:

dao:

@Repository
@Transactional(value=”mysqlEM”)
public class BaseDAOSupport<T> implements BaseDAO<T> {
@SuppressWarnings(“unchecked”)
private Class<T> entityClass = GenericsUtils.getSuperClassGenricType(this.getClass());
@PersistenceContext(unitName=”mysqldb”)
protected EntityManager em;

@Repository
@Transactional(value=”sqlserverEM”)
public class BaseDAOSqlServer<T> implements BaseDAO<T> {
@SuppressWarnings(“unchecked”)
private Class<T> entityClass = GenericsUtils.getSuperClassGenricType(this.getClass());
@PersistenceContext(unitName=”sqlserverdb”)
protected EntityManager em;

看明白什么意思了吧,不解释。

service:

@Service(“menuService”)
public class MenuServiceImpl extends BaseDAOSupport<Tmenu> implements MenuService{

@Service(“umUserService”)
public class UmUserServiceImpl extends BaseDAOSqlServer<UmMrpUser> implements UmUserService{

就这么简单。

controller:

@Controller
@RequestMapping(“/user”)
public class UserController {

@Autowired
private UserService userService;
@Autowired
private UmUserService umUserService;

在一个控制类里面可以同时调用不同的数据库内容。

表现层我就不写了。这个方案可以实现各自事务的提交。

更深入的测试还没发现什么问题,over!

接上一个博文,没有数据库连接池,纯粹用jpa的官方链接。

所以这次要加上连接池本文用Druid连接池来实现多数据源的配置。

persistence.xml 这个文件可以省略了,全部配置在applicationContext.xml 里面:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:aop="http://www.springframework.org/schema/aop"
  5. xmlns:context="http://www.springframework.org/schema/context"
  6. xmlns:jpa="http://www.springframework.org/schema/data/jpa"
  7. xmlns:mvc="http://www.springframework.org/schema/mvc"
  8. xmlns:tx="http://www.springframework.org/schema/tx"
  9. xmlns:util="http://www.springframework.org/schema/util"
  10. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  11. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
  12. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
  13. http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
  14. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
  15. http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd
  16. http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.2.xsd">
  17. <context:annotation-config/>
  18. <context:component-scan base-package="com.tw"/>
  19. <!-- mysql数据源配置 -->
  20. <bean id="mysqlDataSource" class="com.alibaba.druid.pool.DruidDataSource"
  21. init-method="init" destroy-method="close">
  22. <!-- 驱动名称 -->
  23. <property name="DriverClassName" value="com.mysql.jdbc.Driver" />
  24. <!-- JDBC连接串 -->
  25. <property name="url"
  26. value="jdbc:mysql://192.168.132.1:3306/twq?useUnicode=true&characterEncoding=UTF-8" />
  27. <!-- 数据库用户名称 -->
  28. <property name="username" value="ws" />
  29. <!-- 数据库密码 -->
  30. <property name="password" value="unionmanws" />
  31. <!-- 连接池最大使用连接数量 -->
  32. <property name="maxActive" value="20" />
  33. <!-- 初始化大小 -->
  34. <property name="initialSize" value="5" />
  35. <!-- 获取连接最大等待时间 -->
  36. <property name="maxWait" value="60000" />
  37. <!-- 连接池最小空闲 -->
  38. <property name="minIdle" value="2" />
  39. <!-- 逐出连接的检测时间间隔 -->
  40. <property name="timeBetweenEvictionRunsMillis" value="3000" />
  41. <!-- 最小逐出时间 -->
  42. <property name="minEvictableIdleTimeMillis" value="300000" />
  43. <!-- 测试有效用的SQL Query -->
  44. <property name="validationQuery" value="SELECT 'x'" />
  45. <!-- 连接空闲时测试是否有效 -->
  46. <property name="testWhileIdle" value="true" />
  47. <!-- 获取连接时测试是否有效 -->
  48. <property name="testOnBorrow" value="false" />
  49. <!-- 归还连接时是否测试有效 -->
  50. <property name="testOnReturn" value="false" />
  51. </bean>
  52. <!-- 整合mysqljpa -->
  53. <bean id="mysqlEntityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  54. <property name="dataSource" ref="mysqlDataSource"></property>
  55. <property name="packagesToScan" value="com.tw.entity.sys"></property>
  56. <property name="persistenceUnitName" value="mysqldb"></property>
  57. <property name="jpaVendorAdapter">
  58. <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
  59. <property name="showSql" value="true"></property>
  60. </bean>
  61. </property>
  62. <property name="jpaProperties">
  63. <props>
  64. <!--设置外连接抓取树的最大深度 -->
  65. <prop key="hibernate.max_fetch_depth">3</prop>
  66. <prop key="hibernate.jdbc.fetch_size">18</prop>
  67. <prop key="hibernate.jdbc.batch_size">10</prop>
  68. <!-- 自动建表类型 validate|create|create-drop|update -->
  69. <!-- <prop key="hibernate.hbm2ddl.auto">validate</prop> -->
  70. <!-- 是否显示SQL -->
  71. <prop key="hibernate.show_sql">false</prop>
  72. <!-- 显示SQL是否格式化 -->
  73. <prop key="hibernate.format_sql">false</prop>
  74. <!-- 关闭二级缓存 -->
  75. <prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
  76. <!-- 关闭实体字段映射校验 -->
  77. <prop key="javax.persistence.validation.mode">none</prop>
  78. </props>
  79. </property>
  80. </bean>
  81. <bean id="mysqltransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
  82. <property name="entityManagerFactory" ref="mysqlEntityManagerFactory" />
  83. <qualifier value="mysqlEM"/>
  84. </bean>
  85. <tx:annotation-driven transaction-manager="mysqltransactionManager" proxy-target-class="false"/>
  86. <!-- sqlserver数据源配置 -->
  87. <bean id="sqlserverDataSource" class="com.alibaba.druid.pool.DruidDataSource"
  88. init-method="init" destroy-method="close">
  89. <!-- 驱动名称 -->
  90. <property name="DriverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
  91. <!-- JDBC连接串 -->
  92. <property name="url"
  93. value="jdbc:sqlserver://192.168.130.10:1433;DatabaseName=unionman" />
  94. <!-- 数据库用户名称 -->
  95. <property name="username" value="sa" />
  96. <!-- 数据库密码 -->
  97. <property name="password" value="123abc" />
  98. <!-- 连接池最大使用连接数量 -->
  99. <property name="maxActive" value="20" />
  100. <!-- 初始化大小 -->
  101. <property name="initialSize" value="5" />
  102. <!-- 获取连接最大等待时间 -->
  103. <property name="maxWait" value="60000" />
  104. <!-- 连接池最小空闲 -->
  105. <property name="minIdle" value="2" />
  106. <!-- 逐出连接的检测时间间隔 -->
  107. <property name="timeBetweenEvictionRunsMillis" value="3000" />
  108. <!-- 最小逐出时间 -->
  109. <property name="minEvictableIdleTimeMillis" value="300000" />
  110. <!-- 测试有效用的SQL Query -->
  111. <property name="validationQuery" value="SELECT 'x'" />
  112. <!-- 连接空闲时测试是否有效 -->
  113. <property name="testWhileIdle" value="true" />
  114. <!-- 获取连接时测试是否有效 -->
  115. <property name="testOnBorrow" value="false" />
  116. <!-- 归还连接时是否测试有效 -->
  117. <property name="testOnReturn" value="false" />
  118. </bean>
  119. <!-- 整合sqlserverjpa -->
  120. <bean id="sqlserverEntityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  121. <property name="dataSource" ref="sqlserverDataSource"></property>
  122. <property name="packagesToScan" value="com.tw.entity.plan"></property>
  123. <property name="persistenceUnitName" value="sqlserverdb"></property>
  124. <property name="jpaVendorAdapter">
  125. <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
  126. <property name="showSql" value="true"></property>
  127. </bean>
  128. </property>
  129. <property name="jpaProperties">
  130. <props>
  131. <!--设置外连接抓取树的最大深度 -->
  132. <prop key="hibernate.max_fetch_depth">3</prop>
  133. <prop key="hibernate.jdbc.fetch_size">18</prop>
  134. <prop key="hibernate.jdbc.batch_size">10</prop>
  135. <!-- 自动建表类型 validate|create|create-drop|update -->
  136. <!-- <prop key="hibernate.hbm2ddl.auto">validate</prop> -->
  137. <!-- 是否显示SQL -->
  138. <prop key="hibernate.show_sql">false</prop>
  139. <!-- 显示SQL是否格式化 -->
  140. <prop key="hibernate.format_sql">false</prop>
  141. <!-- 关闭二级缓存 -->
  142. <prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
  143. <!-- 关闭实体字段映射校验 -->
  144. <prop key="javax.persistence.validation.mode">none</prop>
  145. </props>
  146. </property>
  147. </bean>
  148. <bean id="sqlservertransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
  149. <property name="entityManagerFactory" ref="sqlserverEntityManagerFactory" />
  150. <qualifier value="sqlserverEM"/>
  151. </bean>
  152. <tx:annotation-driven transaction-manager="sqlservertransactionManager" proxy-target-class="false"/>
  153. </beans>

其他地方按上次的配置不需要做改动。这样就好了。

文章转载自:http://www.loveweir.com/

spring 4 + jpa(hibernate 3/4) + spring mvc 多数据源配置的更多相关文章

  1. Spring Boot + Jpa(Hibernate) 架构基本配置

    本文转载自:https://blog.csdn.net/javahighness/article/details/53055149 1.基于springboot-1.4.0.RELEASE版本测试 2 ...

  2. Spring Boot + JPA(hibernate 5) 开发时,数据库表名大小写问题

      (转载)Spring Boot + JPA(hibernate 5) 开发时,数据库表名大小写问题   这几天在用spring boot开发项目, 在开发的过程中遇到一个问题hibernate在执 ...

  3. Spring Boot 2.x 之 Spring Data JPA, Hibernate 5

    1. Spring Boot常用配置项 基于Spring Boot 2.0.6.RELEASE 1.1 配置属性类 spring.jpa前缀的相关配置项定义在JpaProperties类中, 1.2 ...

  4. Java spring mvc多数据源配置

    1.首先配置两个数据库<bean id="dataSourceA" class="org.apache.commons.dbcp.BasicDataSource&q ...

  5. 【spring boot】12.spring boot对多种不同类型数据库,多数据源配置使用

    2天时间,终于把spring boot下配置连接多种不同类型数据库,配置多数据源实现! ======================================================== ...

  6. spring data jpa hibernate jpa 三者之间的关系

    JPA规范与ORM框架之间的关系是怎样的呢? JPA规范本质上就是一种ORM规范,注意不是ORM框架——因为JPA并未提供ORM实现,它只是制订了一些规范,提供了一些编程的API接口,但具体实现则由服 ...

  7. Spring data jpa hibernate:查询异常java.sql.SQLException: Column '列名' not found

    使用spring boot,jap,hibernate不小心的错误: java.sql.SQLException: Column '列名' not found: 这句话的意思是:找不到此列 为什么会出 ...

  8. 学习Spring Boot:(二十四)多数据源配置与使用

    前言 随着业务量增大,可能有些业务不是放在同一个数据库中,所以系统有需求使用多个数据库完成业务需求,我们需要配置多个数据源,从而进行操作不同数据库中数据. 正文 JdbcTemplate 多数据源 配 ...

  9. spring入门(六)【springMVC中各数据源配置】

    在使用spring进行javaWeb开发的过程中,需要和数据库进行数据交换,为此要经常获取数据库连接,使用JDBC的方式获取数据库连接,使用完毕之后再释放连接,这种过程对系统资源的消耗无疑是很大的,这 ...

随机推荐

  1. Springboot Maven 多模块项目中 @Service跨模块引用失败的问题

    子模块中引用另一个子模块中的Service, @Autowired失败. 添加了模块之间的依赖没解决. 组以后在启动类上加上 @SpringBootApplication(scanBasePackag ...

  2. IE下object元素遮挡div表单

    目前遇到这样的一个问题: 我用ActiveX插件做了一个C#的播放器,要将这个插件放到web浏览器中,然后可以通过前台页面来控制视频的播放,暂停还有回放,这个时候发现object的onclick事件无 ...

  3. 常用PhpStorm 快捷键

    函数列表 打开某一个源码文件后,保证鼠标焦点在源文件内,按键盘组合键: alt + 7 返回原文件导航:双击最上面的工程名即可 PhpStorm折叠文件内所有函数 按下快捷`Ctrl`+`Shift` ...

  4. PHP-Socket-阻塞与非阻塞,同步与异步概念的理解

    1. 概念理解 在进行网络编程时,我们常常见到同步(Sync)/异步(Async),阻塞(Block)/非阻塞(Unblock)四种调用方式:同步:      所谓同步,就是在发出一个功能调用时,在没 ...

  5. CSMA/CD解释与理解

    1. CSMA/CD含义 CSMA/CD即载波监听多点接入/碰撞检测,此协议是使用在总线型网络中的,不同计算机是通过多点接入的方式连接在一起.协议的重点在于监听和碰撞检测. 2. 为什么要监听和碰撞检 ...

  6. PHP中foreach用法详细讲解

    1.foreach是什么? foreach是PHP的一种语法结构,其实就是一个工具,(工具:就是工作的时候用到的器具),那么在程序开发过程中,为了达到程序效果,就用到了foreach. 2.如何用? ...

  7. cocoapods 错误处理

    error: RPC failed; curl 56 SSLRead() return error -36 [!] /usr/bin/git clone https://github.com/Coco ...

  8. 【BZOJ4069】[Apio2015]巴厘岛的雕塑 按位贪心+DP

    [BZOJ4069][Apio2015]巴厘岛的雕塑 Description 印尼巴厘岛的公路上有许多的雕塑,我们来关注它的一条主干道. 在这条主干道上一共有 N 座雕塑,为方便起见,我们把这些雕塑从 ...

  9. Ubuntu 12.04使用uginx+fastcgi-mono-server2部署asp.net 网站

    Ubuntu 12.04使用uginx+fastcgi-mono-server2部署asp.net 网站 1.安装nginx和mono-fastcgi-server2 sodu apt-get  in ...

  10. 石子合并DP

    DP Time Limit:3000MS     Memory Limit:131072KB     64bit IO Format:%lld & %llu Submit Status Pra ...