java - Spring MVC + Spring Security Component Scan -


i have encountered problem mappings getting initialized twice.

here webmvcconfigureradapter

@configuration @enablewebmvc @componentscan("com.beo") public class webmvcconfiguration extends webmvcconfigureradapter {  @override public void addresourcehandlers(final resourcehandlerregistry registry) {     registry.addresourcehandler("/resources/**")             .addresourcelocations("/resources/").setcacheperiod(31556926); }  @override public void configuredefaultservlethandling(         defaultservlethandlerconfigurer configurer) {     configurer.enable(); }  @bean public static propertysourcesplaceholderconfigurer propertyconfigindev() {     return new propertysourcesplaceholderconfigurer(); }  @bean public excelbuilder excelbuilder() {     return new excelbuilder(); }  @bean(name = "multipartresolver") public commonsmultipartresolver multipartresolver() {     commonsmultipartresolver resolver = new commonsmultipartresolver();     resolver.setdefaultencoding("utf-8");     resolver.setmaxuploadsize(100000);     return resolver; }  @bean public viewresolver setupviewresolver(contentnegotiationmanager manager) {     list<viewresolver> resolvers = new arraylist<viewresolver>();      internalresourceviewresolver internalresourceresolver = new internalresourceviewresolver();     internalresourceresolver.setprefix("/web-inf/jsp/");     internalresourceresolver.setsuffix(".jsp");     resolvers.add(internalresourceresolver);      contentnegotiatingviewresolver resolver2 = new contentnegotiatingviewresolver();     resolver2.setviewresolvers(resolvers);     resolver2.setcontentnegotiationmanager(manager);     return resolver2;  } } 

as can see have annotated @componentscan.

now here websecurityconfigureradapter.

@configuration @enablewebsecurity @componentscan("com.beo") public class securityconfiguration extends websecurityconfigureradapter {  @autowired private userdetailsservice userdetailsservice;  @override protected void configure(httpsecurity http) throws exception {     system.out.println("security scan");     http.authorizerequests().antmatchers("/login").permitall()             .antmatchers("/auth/**").authenticated().antmatchers("/sec/**")             .hasrole("admin").and().formlogin().loginpage("/login")             .loginprocessingurl("/j_spring_security_check")             .usernameparameter("email").passwordparameter("password")             .defaultsuccessurl("/auth/panel").failureurl("/login?error")             .and().logout().logouturl("/logout").logoutsuccessurl("/login")             .deletecookies("jsessionid").invalidatehttpsession(true).and()             .headers().frameoptions().sameorigin()             .httpstricttransportsecurity().disable().and()             .sessionmanagement().maximumsessions(1)             .maxsessionspreventslogin(true); }  @override protected void configure(authenticationmanagerbuilder auth)         throws exception {      auth.userdetailsservice(userdetailsservice).passwordencoder(             passwordencoder()); }  @bean protected passwordencoder passwordencoder() {     return new bcryptpasswordencoder(); } } 

i forced annotate websecurityconfigureradapter @componentscan because if don't, getting error regarding autowiring of userdetailsservice.

but configuration, mappings being initialized twice. ideas on how fix this? :(

update

userdetailsservice

@service("userdetailsservice") public class userdetailsserviceimpl implements userdetailsservice {      @autowired     private userdao userdao;      @override     @transactional(readonly = true)     public activeuser loaduserbyusername(string email)             throws usernamenotfoundexception {          useraccounts user = userdao.findbyemail(email);         if (user != null) {             // string password = user.getpassword();              // additional security object information             boolean enabled = user.getstatus().equals(status.active);             boolean accountnonexpired = user.getstatus().equals(status.active);             boolean credentialsnonexpired = user.getstatus().equals(                     status.active);             boolean accountnonlocked = user.getstatus().equals(status.active);              collection<grantedauthority> authorities = new arraylist<grantedauthority>();              (role role : user.getroles()) {                 authorities.add(new simplegrantedauthority(role.getrole()));             }              // spring security object             // org.springframework.security.core.userdetails.user securityuser =             // new user(             // email, password, enabled, accountnonexpired,             // credentialsnonexpired, accountnonlocked, authorities);             activeuser activeuser = new activeuser(user.getemail(),                     user.getpassword(), enabled, accountnonexpired,                     credentialsnonexpired, accountnonlocked, authorities,                     user.getfirstname(), user.getlastname(),                     user.getimagepath());              return activeuser;         } else {             throw new usernamenotfoundexception("user not found!");         }     } } 


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -