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 : 6936
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