Trying to use Spring with JPA and JTA with only Spring Annotation
<p>I am setting up an application that accept a REST call and then does some DB work.  I am trying to use Spring to do everything via annotations, except I would like to keep the persistence.xml file.  However, I am being thrown an error that there is not a Bean called the unitName I have added to the @PersistenceContext.</p>

<pre><code>@Repository
@Transactional
public class UserController implements Serializable {
    private static final long serialVersionUID = 4625223295588959802L;

    @PersistenceContext(unitName="PerfJPASpring")
    private EntityManager em;

    @Transactional
    public void addUser(User user) {
        em.persist(user);
    }

    @Transactional
    public void deleteAll() {
        em.createNamedQuery("User.deleteAll").executeUpdate();
    }

    @Transactional
    public List&lt;User&gt; selectAllRecords() {
        return em.createNamedQuery("User.findAll").getResultList();
    }
}
</code></pre>

<p>The other issue I have is how do I get Spring to use the persistence.xml and not define the DataSource in the LocalContainerEntityManagerFactoryBean.  I have added the Datasource to the App Server.</p>

<pre><code>@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackageClasses=UserController.class)
public class DatabaseConfig  {

    @Bean
    public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
        EclipseLinkJpaVendorAdapter vendorAdapter = new EclipseLinkJpaVendorAdapter();
        vendorAdapter.setGenerateDdl(true);
        vendorAdapter.setShowSql(false);

        LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
        factory.setJpaVendorAdapter(vendorAdapter);
        factory.setPackagesToScan("com.example.jpa.model");
        factory.setDataSource(dataSource());

        Properties jpaProps = new Properties();
        jpaProps.put("eclipselink.weaving", "false");
        factory.setJpaProperties(jpaProps);
        return factory;
    }

    @Bean
    public JpaTransactionManager transactionManager() throws SQLException {
        JpaTransactionManager txManager = new JpaTransactionManager();
        txManager.setEntityManagerFactory(entityManagerFactory().getObject());
        return txManager;
    }

    public DataSource dataSource() {
        try {
            Context initCtx = new InitialContext();
            return (DataSource) initCtx.lookup("jdbc/userdb");
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("Unable to lookup datasource", e);
        }
    }       
}
</code></pre>

<p>The unitName does match that in the persistence.xml file.</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"&gt;
    &lt;persistence-unit name="PerfJPASpring" transaction-type="JTA"&gt;
        &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;
        &lt;jta-data-source&gt;jdbc/userdb&lt;/jta-data-source&gt;
        &lt;class&gt;com.example.jpa.model.User&lt;/class&gt;
    &lt;/persistence-unit&gt;
&lt;/persistence&gt;
</code></pre>

<p>And this is the error I am receiving.</p>

<pre><code>Uncaught init() exception created by servlet [DispatcherServlet] in application [PerfJPASpring]: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'PerfJPASpring' is defined
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:357)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1219)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:751)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:540)
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
    at javax.servlet.GenericServlet.init(GenericServlet.java:244)
    at [internal classes]
</code></pre>

<p>Could point me in the right direction for Spring to use the unitName and how I can avoid specifying the datasource in the Db Config?</p>

<p>Thanks.</p>