IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Boot Java Discussion :

exception not a managed type pour une application spring boot


Sujet :

Spring Boot Java

  1. #1
    Membre actif
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    729
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2006
    Messages : 729
    Points : 250
    Points
    250
    Par défaut exception not a managed type pour une application spring boot
    J'ai développé une application spring boot qui inclue spring securité.

    Voici la classe principale de mon application

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
        @SpringBootApplication
        public class DemoImmobilierBackApplication implements WebMvcConfigurer {
     
        	public static void main(String[] args) {
        		SpringApplication.run(DemoImmobilierBackApplication.class, args);
        	}
     
        	@Bean
        	public CommonsRequestLoggingFilter requestLoggingFilter() {
        	    CommonsRequestLoggingFilter loggingFilter = new CommonsRequestLoggingFilter();
        	    loggingFilter.setIncludeClientInfo(true);
        	    loggingFilter.setIncludeQueryString(true);
        	    loggingFilter.setIncludePayload(true);
        	    loggingFilter.setIncludeHeaders(false);
        	    return loggingFilter;
        	}
     
            @Bean(name="passwordEncoder")
            public PasswordEncoder passwordEncoder() {
                return new BCryptPasswordEncoder();
            }
     
            @Bean
            public DataSource dataSource() {
     
              EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
              return builder.setType(EmbeddedDatabaseType.HSQL).build();
            }
     
            @Bean
            public EntityManagerFactory entityManagerFactory() {
     
              HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
              vendorAdapter.setGenerateDdl(true);
     
              LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
              factory.setJpaVendorAdapter(vendorAdapter);
              factory.setPackagesToScan("com.acme.domain");
              factory.setDataSource(dataSource());
              factory.afterPropertiesSet();
     
              return factory.getObject();
            }
     
            @Bean
            public PlatformTransactionManager transactionManager() {
     
              JpaTransactionManager txManager = new JpaTransactionManager();
              txManager.setEntityManagerFactory(entityManagerFactory());
              return txManager;
            }
     
        //    @Bean
        //    public EntityManagerFactory getEntityManagerFactory() {
        //    	return 
        //    }
     
            /**
             * CORS configuration
             */
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**")
                        .allowedOrigins(
                                "http://localhost:4200"
                        )
                        .allowedMethods(
                                "GET",
                                "PUT",
                                "POST",
                                "DELETE",
                                "PATCH",
                                "OPTIONS"
                        );
            }
     
        }



    Voici la classe userRepository

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
        @Repository
        public interface UserRepository extends JpaRepository<User, Long> {
     
        	  @Query("select u from User u where u.email = :username or u.password = :password")
        	  User findByEmailAndPassword(@Param("username") String email,
        	                                 @Param("password") String password);
     
        	  @Query("select u from User u where u.email = :email")
        	  User findByEmail(@Param("email") String email);
     
        	  @Query("select u from User u where u.email = :email")
        	  public User findByLogin(String email);
     
        	  <S extends User> S saveAndFlush(S entity);
     
        	  void deleteInBatch(Iterable<User> entities);
     
        	  <S extends User> S save(S entity);
     
        	  Optional<User> 	findById(Long id);
        	  boolean 	existsById(Long id);
        	  List<User> findAll();
     
        	  void 	deleteAll();
        	  void 	deleteById(Long id);
        	  void delete(User user);
     
        	  long count();
     
        	}
    Voici un extrait de la classe User

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    import javax.persistence.Entity;
        @Getter
        @Setter
        @Table(name = "USER")
        @Entity
        public class User {
     
            /**
             * the ID of the product.
             */
            @Id
            @Column(name = "USER_ID")
            @GeneratedValue(strategy= GenerationType.IDENTITY)
            private Long id;
            /**
             * male (M) or Female (F).
             */
            @Column(name = "GENDER")
            private String gender;
     
            /**
             * last name.
             */
            @Column(name = "LASTNAME")
            private String lastName;
     
     
            /**
             * first name.
             */
            @Column(name = "FIRSTNAME")
            private String firstName;   
            /**
             * email.
             */
            @Column(name = "EMAIL")
    Voici le fichier application.properties
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
        spring.datasource.url=jdbc:mysql://localhost:3306/testdb?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
        spring.datasource.username=root
        spring.datasource.password=@Marwen1
        spring.datasource.driver-class-name=com.mysql.jdbc.Driver
        spring.jpa.show-sql=true
        spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl
        spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
        spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
        logging.level.org.springframework.web.filter.CommonsRequestLoggingFilter=DEBUG
     
        spring.main.allow-bean-definition-overriding=true

    Voici l'arborescence de mon projet

    Nom : Capture d’écran 2020-10-03 à 10.07.34.png
Affichages : 6628
Taille : 80,5 Ko


    Et voici l'exception que j'obtiens


    Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webSecurityConfig' defined in file [/Users/admin/GIT/demoImmobilierBack/target/classes/com/example/demoImmobilierBack/WebSecurityConfig.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDetailsService': Unsatisfied dependency expressed through field 'userServiceImpl'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'userRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.example.demoImmobilierBack.model.User






    [1]: https://i.stack.imgur.com/ff2ou.png

  2. #2
    Membre averti
    Homme Profil pro
    Architecte technique
    Inscrit en
    Mai 2020
    Messages
    329
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Architecte technique

    Informations forums :
    Inscription : Mai 2020
    Messages : 329
    Points : 443
    Points
    443
    Par défaut
    Bonjour,

    Etes vous sur que com.example.demoImmobilierBack.model.User soit "scanné" par Spring ?
    Il faut resneigner les @Entity à l'entity manager de votre projet, Spring peux se charger de cela si vous lui renseignez le bon package mais je vois que vous renseignez "com.acme.domain"

  3. #3
    Membre actif
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    729
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2006
    Messages : 729
    Points : 250
    Points
    250
    Par défaut
    Bonjour,
    oui effectivement, j'ai été étourdi, merci

  4. #4
    Membre averti
    Homme Profil pro
    Architecte technique
    Inscrit en
    Mai 2020
    Messages
    329
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Architecte technique

    Informations forums :
    Inscription : Mai 2020
    Messages : 329
    Points : 443
    Points
    443
    Par défaut
    Super.

    Pensez à maquer la discussion comme résolue si ce n'est pas déjà fait.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 2
    Dernier message: 01/12/2020, 14h28
  2. Changer le contexte d'une application Spring boot
    Par momjunior dans le forum Spring Boot
    Réponses: 1
    Dernier message: 17/12/2019, 10h55
  3. Déploiement d'une application Spring Boot sur Heroku
    Par k_oumarou dans le forum Spring Boot
    Réponses: 4
    Dernier message: 24/05/2019, 12h50
  4. Réponses: 8
    Dernier message: 30/08/2017, 15h23
  5. EDeployement d'une application spring boot(.jar) sur ubuntu server
    Par ben22222222 dans le forum Spring Boot
    Réponses: 5
    Dernier message: 14/12/2016, 15h47

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo