devdeep1987

MutiboServer

Dec 30th, 2014
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.24 KB | None | 0 0
  1. Error:
  2. Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.setFilterChainProxySecurityConfigurer(org.springframework.security.config.annotation.ObjectPostProcessor,java.util.List) throws java.lang.Exception; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webSecurityConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private showcase.CustomUserDetailsService showcase.WebSecurityConfiguration.customUserDetailsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDetailsService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: showcase.AppUserRepository showcase.CustomUserDetailsService.repository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appUserRepository': Cannot create inner bean '(inner bean)#6bd8d7e8' 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)#6bd8d7e8': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.entityManagerFactory(org.springframework.orm.jpa.JpaVendorAdapter)] threw exception; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.sql.DataSource] is defined
  3.  
  4.  
  5.  
  6. Application.java
  7.  
  8. @EnableAutoConfiguration
  9. @EnableJpaRepositories(basePackageClasses = AppUserRepository.class)
  10. @Configuration
  11. @ComponentScan
  12. public class Application {
  13.  
  14.     public static void main(String[] args) {
  15.         SpringApplication.run(Application.class, args);
  16.     }
  17.  
  18.     @Bean
  19.     MultipartConfigElement multipartConfigElement() {
  20.         MultiPartConfigFactory factory = new MultiPartConfigFactory();
  21.         factory.setMaxFileSize("128KB");
  22.         factory.setMaxRequestSize("128KB");
  23.         return factory.createMultipartConfig();
  24.     }
  25.  
  26. }
  27.  
  28. AppUserRepository.java
  29.  
  30. @Repository
  31. public interface AppUserRepository extends CrudRepository<AppUser, Long>{
  32.  
  33.     public AppUser findByUserName(String username);
  34.     public void delete(AppUser user);
  35. }
  36.  
  37.  
  38. WebSecurityConfiguration.java
  39.  
  40. @Configuration
  41. @EnableWebSecurity
  42. public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
  43.     @Autowired
  44.     private CustomUserDetailsService customUserDetailsService;
  45.         @Override
  46.         @Autowired
  47.         protected void configure(AuthenticationManagerBuilder auth) throws Exception {
  48.             // @formatter:off
  49.  
  50.                     auth.userDetailsService(customUserDetailsService);
  51.  
  52.            
  53.             // @formatter:on
  54.         }
  55.  
  56.  
  57. CustomUserDetailsService.java
  58.  
  59. @Service("userDetailsService")
  60. public class CustomUserDetailsService implements UserDetailsService {
  61.     @Autowired
  62.     AppUserRepository repository;
  63.  
  64.     @Autowired
  65.     private UserService userService;
  66.  
  67.  
  68.     private static final Logger logger = LoggerFactory.getLogger(CustomUserDetailsService.class);
  69.  
  70.     static final PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
  71.     @Override
  72.     public UserDetails loadUserByUsername(String name) throws UsernameNotFoundException {
  73.         logger.info("username:"+name);
  74.         AppUser u = repository.findByUserName(name);
  75.         if (u == null)
  76.             throw new UsernameNotFoundException("User details not found with this username: " + name);
  77.         String username = u.getUsername();
  78.         String password = u.getPassword();
  79.         List authList = new ArrayList();
  80.         authList.add(new SimpleGrantedAuthority("USER"));
  81.  
  82.         User user = new User(username, password, authList);
  83.  
  84.         return user;
  85.     }
  86.  
  87.  
  88. UserService.java
  89.  
  90. @Service("userService")
  91. public class UserService {
  92.  
  93.     @Autowired
  94.     AppUserRepository repository;
  95.  
  96.     public AppUser registerNewAppUser(AppUser user) {
  97.         AppUser u = repository.findByUserName(user.getUsername());
  98.         if (u!=null)
  99.             return null;
  100.         return repository.save(user);
  101.     }
Advertisement
Add Comment
Please, Sign In to add comment