<tfoot id='hcIpb'></tfoot>
    1. <i id='hcIpb'><tr id='hcIpb'><dt id='hcIpb'><q id='hcIpb'><span id='hcIpb'><b id='hcIpb'><form id='hcIpb'><ins id='hcIpb'></ins><ul id='hcIpb'></ul><sub id='hcIpb'></sub></form><legend id='hcIpb'></legend><bdo id='hcIpb'><pre id='hcIpb'><center id='hcIpb'></center></pre></bdo></b><th id='hcIpb'></th></span></q></dt></tr></i><div id='hcIpb'><tfoot id='hcIpb'></tfoot><dl id='hcIpb'><fieldset id='hcIpb'></fieldset></dl></div>

      <legend id='hcIpb'><style id='hcIpb'><dir id='hcIpb'><q id='hcIpb'></q></dir></style></legend>

        <small id='hcIpb'></small><noframes id='hcIpb'>

        • <bdo id='hcIpb'></bdo><ul id='hcIpb'></ul>

        PersistenceAnnotationBeanPostProcessor 有什么用处吗?

        Is PersistenceAnnotationBeanPostProcessor of any use at all?(PersistenceAnnotationBeanPostProcessor 有什么用处吗?)
      1. <i id='5NWpc'><tr id='5NWpc'><dt id='5NWpc'><q id='5NWpc'><span id='5NWpc'><b id='5NWpc'><form id='5NWpc'><ins id='5NWpc'></ins><ul id='5NWpc'></ul><sub id='5NWpc'></sub></form><legend id='5NWpc'></legend><bdo id='5NWpc'><pre id='5NWpc'><center id='5NWpc'></center></pre></bdo></b><th id='5NWpc'></th></span></q></dt></tr></i><div id='5NWpc'><tfoot id='5NWpc'></tfoot><dl id='5NWpc'><fieldset id='5NWpc'></fieldset></dl></div>
        <tfoot id='5NWpc'></tfoot>

            <small id='5NWpc'></small><noframes id='5NWpc'>

              <tbody id='5NWpc'></tbody>

            <legend id='5NWpc'><style id='5NWpc'><dir id='5NWpc'><q id='5NWpc'></q></dir></style></legend>

                  <bdo id='5NWpc'></bdo><ul id='5NWpc'></ul>
                  本文介绍了PersistenceAnnotationBeanPostProcessor 有什么用处吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  根据它的JavaDoc,PersistenceAnnotationBeanPostProcessor 似乎负责用注解@PersistenceContext 注入EntityManager.它似乎暗示没有在 Spring 应用程序上下文 xml 中声明此 bean,@PersistenceContext 注释将不起作用.

                  According to its JavaDoc, PersistenceAnnotationBeanPostProcessor seems to be responsible for injecting the EntityManager with the annotation @PersistenceContext. It appears to imply without this bean declared in the Spring application context xml, the @PersistenceContext annotation won't work.

                  但是,根据我的实验,事实并非如此.

                  However, based on my experiments, this is not the truth.

                  <persistence 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_1_0.xsd"
                      version="1.0">
                      <persistence-unit name="default" transaction-type="RESOURCE_LOCAL" />
                  </persistence>
                  

                  Spring 应用程序上下文 XML

                  <context:component-scan base-package="com.test.dao" />
                  
                  <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
                      <property name="dataSource" ref="dataSource"/>
                      <property name="persistenceUnitName" value="default"/>
                      <property name="jpaVendorAdapter">
                          <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                              <property name="showSql" value="true"/>
                              <property name="generateDdl" value="true"/>
                              <property name="databasePlatform" value="org.hibernate.dialect.DerbyDialect"/>
                          </bean>
                      </property>
                  </bean>
                  
                  <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
                      <property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver"/>
                      <property name="url" value="jdbc:derby://localhost:1527/c:derbydbmydb"/>
                      <property name="username" value="APP"/>
                      <property name="password" value="APP"/>
                  </bean>
                  
                  <tx:annotation-driven/>
                  
                  <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
                      <property name="entityManagerFactory" ref="entityManagerFactory" />
                  </bean>
                  
                  <!-- 
                      <bean id="persistenceAnnotation" class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
                   -->
                  

                  UserDaoImpl

                  @Repository("userDao")
                  public class UserDaoImpl implements UserDao {
                  
                      @PersistenceContext
                      protected EntityManager entityManager;
                  
                      @Transactional
                      public void save(User user) {
                              entityManager.persist(user);
                      }
                  }
                  

                  无论我注释或取消注释persistenceAnnotation bean,结果都是一样的.把豆子留在身边也无妨,但是这豆子有什么用呢?

                  Whether I comment or uncomment the persistenceAnnotation bean, the result is the same. It doesn't hurt to leave the bean around, but what's the use of this bean?

                  我使用的是 Spring 3.0.5.

                  I am using Spring 3.0.5.

                  有人能提供一个取出这个 bean 会导致失败的场景吗?

                  Could someone provide a scenario where taking out this bean will result in failure?

                  我也不喜欢仅仅为了愚弄 Spring 而创建一个空的持久化单元.幸运的是,这个问题已经在 Spring 3.1.0 中得到解决.

                  Also I am not fond of creating an empty persistence unit just to fool Spring. Luckily this problem has been addressed in Spring 3.1.0.

                  推荐答案

                  PersistenceAnnotationBeanPostProcessor 元素透明激活.准确地说,是 <context:annotation-config/> 元素激活了 bean,但是这个元素又被 <context:component-scan/><透明地激活了/代码>.

                  The PersistenceAnnotationBeanPostProcessor transparently activated by the <context:component-scan /> element. To be precise it's the <context:annotation-config /> element that activates the bean but this element in turn gets transparently activated by <context:component-scan />.

                  这篇关于PersistenceAnnotationBeanPostProcessor 有什么用处吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)

                  <small id='4zFse'></small><noframes id='4zFse'>

                  <i id='4zFse'><tr id='4zFse'><dt id='4zFse'><q id='4zFse'><span id='4zFse'><b id='4zFse'><form id='4zFse'><ins id='4zFse'></ins><ul id='4zFse'></ul><sub id='4zFse'></sub></form><legend id='4zFse'></legend><bdo id='4zFse'><pre id='4zFse'><center id='4zFse'></center></pre></bdo></b><th id='4zFse'></th></span></q></dt></tr></i><div id='4zFse'><tfoot id='4zFse'></tfoot><dl id='4zFse'><fieldset id='4zFse'></fieldset></dl></div>

                  <tfoot id='4zFse'></tfoot>

                      <bdo id='4zFse'></bdo><ul id='4zFse'></ul>

                      <legend id='4zFse'><style id='4zFse'><dir id='4zFse'><q id='4zFse'></q></dir></style></legend>
                        <tbody id='4zFse'></tbody>