java – required a bean named ‘entityManagerFactory’ that could not be found

. ____ _ __ _ insira o código aqui
/ / __ _ () __ __ _
( ( )_
| ‘_ | ‘| | ‘ / ` |
/ __)| |)| | | | | || (
| | ) ) ) )
‘ || .__|| ||| |_, | / / / /
=========|
|==============|
/=////
:: Spring Boot :: (v2.1.12.RELEASE)

2021-04-05 14:07:12.362 INFO 19212 — ( restartedMain) c.t.s.DesafioSupply.Application : Starting Application on spon190100264 with PID 19212 (C:Usersjose.leocadioDesktopDesafioSupplyAgroTOTVSDesafioSupplytargetclasses started by jose.leocadio in C:Usersjose.leocadioDesktopDesafioSupplyAgroTOTVSDesafioSupply)
2021-04-05 14:07:12.368 INFO 19212 — ( restartedMain) c.t.s.DesafioSupply.Application : No active profile set, falling back to default profiles: default
2021-04-05 14:07:12.688 INFO 19212 — ( restartedMain) .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set ‘spring.devtools.add-properties’ to ‘false’ to disable
2021-04-05 14:07:12.689 INFO 19212 — ( restartedMain) .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the ‘logging.level.web’ property to ‘DEBUG’
2021-04-05 14:07:17.693 INFO 19212 — ( restartedMain) .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-04-05 14:07:18.103 INFO 19212 — ( restartedMain) .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 395ms. Found 3 JPA repository interfaces.
2021-04-05 14:07:20.148 INFO 19212 — ( restartedMain) faultConfiguringBeanFactoryPostProcessor : No bean named ‘errorChannel’ has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.
2021-04-05 14:07:20.167 INFO 19212 — ( restartedMain) faultConfiguringBeanFactoryPostProcessor : No bean named ‘integrationHeaderChannelRegistry’ has been explicitly defined. Therefore, a default DefaultHeaderChannelRegistry will be created.
2021-04-05 14:07:20.781 INFO 19212 — ( restartedMain) trationDelegate$BeanPostProcessorChecker : Bean ‘org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration’ of type (org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$633c801a) is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-04-05 14:07:21.210 INFO 19212 — ( restartedMain) trationDelegate$BeanPostProcessorChecker : Bean ‘integrationDisposableAutoCreatedBeans’ of type (org.springframework.integration.config.annotation.Disposables) is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-04-05 14:07:21.365 INFO 19212 — ( restartedMain) trationDelegate$BeanPostProcessorChecker : Bean ‘org.springframework.integration.config.IntegrationManagementConfiguration’ of type (org.springframework.integration.config.IntegrationManagementConfiguration$$EnhancerBySpringCGLIB$$ce2e3b49) is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-04-05 14:07:21.446 INFO 19212 — ( restartedMain) trationDelegate$BeanPostProcessorChecker : Bean ‘org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration$IntegrationJmxConfiguration’ of type (org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration$IntegrationJmxConfiguration$$EnhancerBySpringCGLIB$$a9c04669) is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-04-05 14:07:21.485 INFO 19212 — ( restartedMain) trationDelegate$BeanPostProcessorChecker : Bean ‘org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration’ of type (org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration$$EnhancerBySpringCGLIB$$e2a7ef36) is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-04-05 14:07:21.543 INFO 19212 — ( restartedMain) trationDelegate$BeanPostProcessorChecker : Bean ‘mbeanServer’ of type (com.sun.jmx.mbeanserver.JmxMBeanServer) is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-04-05 14:07:25.746 INFO 19212 — ( restartedMain) o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-04-05 14:07:25.834 INFO 19212 — ( restartedMain) o.apache.catalina.core.StandardService : Starting service (Tomcat)
2021-04-05 14:07:25.835 INFO 19212 — ( restartedMain) org.apache.catalina.core.StandardEngine : Starting Servlet engine: (Apache Tomcat/9.0.30)
2021-04-05 14:07:26.874 INFO 19212 — ( restartedMain) o.a.c.c.C.(Tomcat).(localhost).(/) : Initializing Spring embedded WebApplicationContext
2021-04-05 14:07:26.874 INFO 19212 — ( restartedMain) o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 14185 ms
2021-04-05 14:07:27.942 INFO 19212 — ( restartedMain) o.s.s.c.ThreadPoolTaskScheduler : Initializing ExecutorService ‘taskScheduler’
2021-04-05 14:07:32.596 WARN 19212 — ( restartedMain) ConfigServletWebServerApplicationContext : Exception encountered during context initialization – cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘enderecoController’: Unsatisfied dependency expressed through field ‘service’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘enderecoService’: Unsatisfied dependency expressed through field ‘repository’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘enderecoRepository’: Cannot create inner bean ‘(inner bean)#3ed12fb9’ of type (org.springframework.orm.jpa.SharedEntityManagerCreator) while setting bean property ‘entityManager’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘(inner bean)#3ed12fb9’: Cannot resolve reference to bean ‘entityManagerFactory’ while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘entityManagerFactory’ available
2021-04-05 14:07:32.608 INFO 19212 — ( restartedMain) o.s.s.c.ThreadPoolTaskScheduler : Shutting down ExecutorService ‘taskScheduler’
2021-04-05 14:07:32.640 INFO 19212 — ( restartedMain) o.apache.catalina.core.StandardService : Stopping service (Tomcat)
2021-04-05 14:07:32.763 INFO 19212 — ( restartedMain) ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.
2021-04-05 14:07:33.228 ERROR 19212 — ( restartedMain) o.s.b.d.LoggingFailureAnalysisReporter :


APPLICATION FAILED TO START


Description:

Field repository in com.totvs.supplyagro.DesafioSupply.Cadastros.Endereco.domain.EnderecoService required a bean named ‘entityManagerFactory’ that could not be found.

The injection point has the following annotations:
– @org.springframework.beans.factory.annotation.Autowired(required=true)

Action:

Consider defining a bean named ‘entityManagerFactory’ in your configuration.

Process finished with exit code 1

java – Spring: GCP and JPA – EntityManagerFactory missing

I have a functional implementation of Spring Boot with Tomcat which handles very well in a JAR file in a Linux environment. The same code does not work with Google Cloud. I'm trying to get JPA to work.

Google Cloud prefers Jetty to Tomcat. It may be related to my problem, but I don't know how to solve it. I have the recommended default conversion from a standard Spring Boot JAR to a WAR version for AppEngine from Google Cloud. My dependencies work well if I try them in a predefined project from the spring.io site. I'm not using databases, so I deleted MySQL, which is the default.

My problem is related to a missing EntityManagerFactory. Since I am trying to keep this post brief, I simply include what I think is vital. You can find most of the full project at: https://github.com/shatterblast/spring-sylveria_fix-search

Basically, I cannot display the admin console for this GCP project. Both the project and the administration console respond with a 503 from a request. There is no error message at startup and it is running properly. From tweaking the code, I found the EntityManager bean like the problem itself. Renaming the beans did not help.

Thank you.

import com.weslange.springboot.sylveria.entity.Gamer;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;

@Repository
public class GamerDAOHibernateImpl implements GamerDAO {

    private EntityManager entityManager;

    @Autowired
    public GamerDAOHibernateImpl( EntityManager theEntityManager ) {
        entityManager = theEntityManager;
    }

    @Override
    public Gamer findById( int id ) {
        Session currentSession = entityManager.unwrap( Session.class );
        Gamer gamer = currentSession.get( Gamer.class, id );
        return gamer;
    }

    @Override
    public void save( Gamer gamer ) {
        Session currentSession = entityManager.unwrap( Session.class );
        currentSession.saveOrUpdate( gamer );
    }

}

.

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;

@Repository
public class TokenDAOHibernateImpl implements TokenDAO {

    private EntityManager entityManager;

    @Autowired
    public TokenDAOHibernateImpl(EntityManager theEntityManager) {
        entityManager = theEntityManager;
    }

}

.

import com.weslange.springboot.sylveria.SylveriaServerApplication;
import com.weslange.springboot.sylveria.entity.Token;
import com.weslange.springboot.sylveria.service.GamerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


@RestController
@RequestMapping( "https://stackoverflow.com/" )
public class TokenRestController {

    private static final Logger logger = LoggerFactory.getLogger( SylveriaServerApplication.class );

    private GamerService gamerService;

    @Autowired
    public TokenRestController( GamerService gamerService ) {
        gamerService = gamerService;
    }

    @PostMapping( "https://stackoverflow.com/" )
    public HashMap addEmployee( @RequestBody Token token, HttpServletRequest request ) {

        HashMap returnMap = new HashMap();
        returnMap.put( "sylveriaConnectionSuccess", "true" );

        return returnMap;

    }

}

java – EntityManager NULL with @PersistenceContext and with EntityManagerFactory

This week, I'm creating a project with the following features: maven War Project with jdk 1.8, RedHatJboss EAP 7.1 Application Server, Oracle DB 12c.

As you can see in the pom file, I use Red Hat online repositories for the jboss eap 7.1 release.

The problem I have is that when creating or injecting EntityManager, it's always nulland eager to use it (for example: em.persit(entidad)) throw a NullPointerException exactly on the line where it is used.

Pom file



    4.0.0
    co.com.company
    AppServices
    0.0.1-SNAPSHOT
    war
    AppServices
    
        UTF-8
    2.0.1.Final
        7.1.5.GA
        3.8.1
        3.0.0-M3
        3.2.3
        1.8
        1.8
    
    
        
            
                org.jboss.bom
                jboss-eap-javaee7-with-tools
                ${version.jboss.bom}
                pom
                import
            
            
                org.jboss.eap
                wildfly-ejb-client-legacy-bom
                ${version.jboss.bom}-redhat-00002
                pom
                import
            
        
    
    
        
            org.jboss.resteasy
            resteasy-jaxrs
            provided
        
        
            org.hibernate
            hibernate-validator
            provided
        
        
            org.hibernate
            hibernate-entitymanager
            provided
        
        
            org.jboss.eap
            wildfly-ejb3
            provided
        
    
    
        ${project.artifactId}
        
            
                maven-war-plugin
                ${version.war.plugin}
                
                    false
                
            
            
                maven-clean-plugin
                3.1.0
            
            
                org.apache.maven.plugins
                maven-compiler-plugin
                ${version.compiler.plugin}
                
                    ${maven.compiler.source}
                    ${maven.compiler.target}
                
            
            
                maven-install-plugin
                3.0.0-M1
            
            
                org.wildfly.plugins
                wildfly-maven-plugin
                ${version.wildfly.maven.plugin}
                true
                
                    true
                
            
        
    
    
    
    
        
            jboss-eap-repository-group
            JBoss EAP Maven Repository
            https://maven.repository.redhat.com/ga/
            default
            
                true
                never
            
            
                true
                never
            
        
    
    
        
            jboss-eap-repository-group
            JBoss EAP Maven Repository
            https://maven.repository.redhat.com/ga/
            
                true
            
            
                true
            
        
    

Persistence.xml file


   
      org.hibernate.ejb.HibernatePersistence
      java:jboss/datasources/AppServicesDS
      co.com.company.appservices.persistencia.entidades.comun.UnaEntidad
      false
      
        
            
            
            
            
        
   

L & # 39; entity

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "NOMBRE_TABLA")
public class NombreTabla implements IEntidad, Serializable{

    @Id
    @Column(name = "idNombreTabla")
    private Integer id;

    @Column(name = "descripcion")
    private String descripcion;

//Constructor y metodos de acceso
}

Repository interface

public interface IRepositorio> extends Serializable {
    E buscarPorId(K id);
    void crear(E entidad);
    void eliminar(E entidad);
    E salvarOActualizar(E entidad);
}

Abstract class repository

public abstract class Repositorio> implements IRepositorio{
    private Class entidad;

    public Repositorio(Class entidad) {
        this.entidad = entidad;
    }

    protected abstract EntityManager getEntityManager();

    @Override
    public void crear(E entidad) {
        getEntityManager().persist(entidad); //Aca se genera la excepcion
    }
}

Setting up a repository

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

public class NombreTablaRepositorio extends Repositorio{

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

    public NombreTablaRepositorio() {
        super(NombreTabla.class);
    }

    @Override
    protected EntityManager getEntityManager() {
        return this.em;
    }
}

The complete error is:

01:12:01,283 ERROR (io.undertow.request) (default task-3) UT005023: Exception handling request to /AppServices/rest/administracion/nombres-tablas: org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
    at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:78)
    at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:222)
    at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:179)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:422)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:213)
    at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:228)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
    at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
    at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
    at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
    at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
    at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
    at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
    at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
    at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:326)
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:812)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
    at co.com.company.appservices.persistencia.repositorio.Repositorio.crear(Repositorio.java:28)
    at co.com.company.appservices.negocio.administracion.impl.AdministracionTabla.crearNombreTabla(AdministracionTabla.java:29)
    at co.com.company.appservices.rest.administracion.facade.TablaService.crearNombreTabla(TablaService.java:38)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)
    at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295)
    at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249)
    at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:406)
    ... 44 more

I appreciate your cooperation.

spring mvc – Error while creating the bean with the name & # 39; entityManagerFactory & # 39; defined in com.springmvc.app.configuration.ApplicationConfig: The invocation of the init method failed.

I'm learning to use spring MVC and for that I have created 3 configuration files: WebInitializer, MvcConfig, ApplicationConfig

My ApplicationConfig:

package com.springmvc.app.configuration;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@EnableWebMvc
@Configuration
@ComponentScan (basePackages = "com.springmvc")
@EnableJpaRepositories ("com.springmvc.app.dao")
Public class ApplicationConfig {
@Bean
public DataSource dataSource () {
System.out.println ("in the data file");
DriverManagerDataSource dataSource = new DriverManagerDataSource ();
dataSource.setDriverClassName ("com.mysql.jdbc.Driver");
dataSource.setUrl ("jdbc: mysql: // localhost: 3306 / database");
dataSource.setUsername ("root");
dataSource.setPassword ("");
return dataSource;
}

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory () {
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter ();
vendorAdapter.setGenerateDdl (true);
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean ();
factory.setJpaVendorAdapter (vendorAdapter);
factory.setPackagesToScan ("com.springmvc.app.model");
factory.setDataSource (dataSource ());
factory return;
}

@Bean
public PlatformTransactionManager transactionManager (EntityManagerFactory emf) {
JpaTransactionManager transactionManager = new JpaTransactionManager ();
transactionManager.setEntityManagerFactory (emf);
return transactionManager;
}
}

I have correctly configured the componentscan and used the @EnableJpaRepositories to access DAO …

Here is my MvcConfig:

package com.springmvc.app.configuration;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigure;

@EnableWebMvc
@Configuration
Public class MvcConfig implements WebMvcConfigure {
public void configureViewResolvers (ViewResolverRegistry registry) {
registry.jsp ("/ WEB-INF / views /", ".jsp");
}
}

Finally here is my WebInitializer:

package com.springmvc.app.configuration;

import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

Public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
Protected class[]    getRootConfigClasses () {
return null;
}

@Override
Protected class[]    getServletConfigClasses () {
return the new class[] {ApplicationConfig.class, MvcConfig.class};
}

@Override
protected chain[] getServletMappings () {
return a new string[] { "/"};
}
}

I return a class[] with ApplicationConfig and MvcConfig …
I've added a simple repository file

package com.springmvc.app.dao;

import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.springmvc.app.model.No person;


public interface PersonRepository extends JpaRepository  {
listing findByNomAndPrenom (String name, String firstname);

@Query ("select p in Person p where p.name =? 1")
Nobody findByNom (String name);
}

And a controller:

package com.springmvc.app.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.springmvc.app.dao.PersonRepository;
import com.springmvc.app.model.No person;

@Controller
Public class PersonController {
@Autowired
personRepository private personRepository;

@RequestMapping (value = "/ add", method = RequestMethod.GET, params = {"name", "firstname"})
public ModelAndView sayHello (@RequestParam (value = "name")) string name,
@RequestParam (value = "firstname") Firstname string) {
Person p1 = new Person (name, first name);
personRepository.save (p1);
ModelAndView mv = new ModelAndView ();
mv.setViewName ("confirm");
mv.addObject ("name", name);
mv.addObject ("firstname", firstname);
return mv;
}

@RequestMapping (value = "/ showAll")
public ModelAndView showAll () {
ArrayList al = (ArrayList) personRepository.findAll ();
ModelAndView mv = new ModelAndView ();
mv.setViewName ("result");
mv.addObject ("tab", al);
return mv;
}

@RequestMapping (value = "/ showAllByPage")
public ModelAndView showAllByPage (@PathVariable int i, @PathVariable int j) {
Page people = personRepository.findAll (PageRequest.of (i, j));
ModelAndView mv = new ModelAndView ();
mv.setViewName ("result");
mv.addObject ("tab", people);
return mv;
}

@RequestMapping (value = "/ showAllByPage")
public ModelAndView showAllByPage () {
listing people = personRepository.findAll (Sort.by ("name"). descending ());
ModelAndView mv = new ModelAndView ();
mv.setViewName ("result");
mv.addObject ("tab", people);
return mv;
}

@RequestMapping (value = "/ showSome")
public ModelAndView showSome (@RequestParam (value = "name") String name, @RequestParam (value = "firstname") String firstname) {
ArrayList al = (ArrayList) personRepository.findByNameAndName (last name, first name);
ModelAndView mv = new ModelAndView ();
mv.setViewName ("result");
mv.addObject ("tab", al);
return mv;
}
}

Finally, I added the required dependencies:



    4.0.0
    com.springmvc
    app
    step03SpringMvcModel
    war
    BUILD-1.0.0-SNAPSHOT
    
        1.6
        5.1.1. RELEASE
        1.6.10
        1.6.6
    
    
        
        
            org.springframework
            spring-webmvc
            $ {org.springframework-version}
        

        
        
            org.aspectj
            aspectjrt
            $ {org.aspectj-version}
        

        
        
            org.slf4j
            slf4j-api
            $ {org.slf4j-version}
        
        
            org.slf4j
            JCL-over-slf4j
            $ {org.slf4j-version}
            runtime
        
        
            org.slf4j
            slf4j-log4j12
            $ {org.slf4j-version}
            runtime
        
        
            log4j
            log4j
            1.2.15
            
                
                    javax.mail
                    mail
                
                
                    javax.jms
                    jms
                
                
                    com.sun.jdmk
                    jmxtools
                
                
                    com.sun.jmx
                    jmxri
                
            
            runtime
        

        
        
            javax.inject
            javax.inject
            1
        

        
        
            javax.servlet
            servlet-api
            2.5
            provided
        
        
            javax.servlet.jsp
            jsp-api
            2.1
            provided
        
        
            javax.servlet
            jstl
            1.2
        

        
        
            org.springframework.data
            spring-data-jpa
            2.0.6. RELEASE
        
        
            org.hibernate.javax.persistence
            hibernate-jpa-2.1-api
            1.0.0.Final
        
        
            mysql
            mysql-connector-java
            05/01/46
        
        
            org.hibernate
            Hibernation-core
            5.3.6.Final
        
        
            org.hibernate.common
            hibernate-commons-annotations
            5.0.1.Final
        

        
        
            JUnit
            JUnit
            4.7
            test
        
    
    
        
            
                maven-eclipse-plugin
                2.9
                
                    
                        org.springframework.ide.eclipse.core.springnature
                    
                    
                        org.springframework.ide.eclipse.core.springbuilder
                    
                    true
                    true
                
            
            
                org.apache.maven.plugins
                maven-compiler-plugin
                2.5.1
                
                    1.6
                    1.6
                    -Xlint: everything
                    true
                    true
                
            
            
                org.codehaus.mojo
                exec-maven-plugin
                1.2.1
                
                    org.test.int1.Main
                
            
        
    

In the path to Javabuild, the version of JDK is 9.0.4 and in the facets of the project, the Java version used is 1.8.
I have surely made a mistake or forgotten something in the process because I get this error message:

org.springframework.beans.factory.BeanCreationException: Error creating a bean with the name & # 39; entityManagerFactory & # 39; defined in com.springmvc.app.configuration.ApplicationConfig: The invocation of the init method failed; nested exception is java.lang.NoClassDefFoundError: javax / xml / bind / JAXBException

Thank you for your help.