java - Spring profile default behaviour -


i have spring profile "dev" , thats profile have , not want create "production" profile. when profile "dev" type of bean spring security initiated (which in memory guest user , userdetails bean)

but if no spring profile provided in tomcat startup, case in production, app continue doing(using ldap authenticatin provider).

is there way define "default" bean behaviour without needing provide profile @ start up? or can @ code below , suggest different solution maybe.

@autowired public void configureglobal(final authenticationmanagerbuilder auth, final authenticationprovider provider) throws exception {          auth                 .erasecredentials(false)                 .authenticationprovider(provider)                 .authenticationprovider(jwtconfig.jwtauthenticationprovider()); }   @bean public userdetailsservice userdetailsservice() {     final ldapuserdetailsservice ldapuserdetailsservice = new ldapuserdetailsservice(ldapusersearch(), ldapauthoritiespopulator());     return new compositeuserdetailsservice(arrays.aslist(technicaluserdetailsservice(), ldapuserdetailsservice)); }  @bean @profile("dev") public userdetailsservice devuserdetailsservice() {  useanonymous = true;         inmemoryuserdetailsmanagerbuilder b = new inmemoryuserdetailsmanagerbuilder()                 .withuser("user").password("password").authorities(role_user, role_admin).and();          return new compositeuserdetailsservice(arrays.aslist(b.build(),                 technicaluserdetailsservice()));  } @bean public authenticationprovider ldapauthenticationprovider() {     final bindauthenticator ba = new bindauthenticator((baseldappathcontextsource) contextsource());     ba.setusersearch(ldapusersearch());     return new ldapauthenticationprovider(ba, ldapauthoritiespopulator()); } 

i think there misunderstanding of @profile does. beans marked @profile loaded when profile active, other beans (without @profile) still loaded, regardless of chosen profile.

i see few ways solve this:

1) mark beans @profile("dev") @primary spring knows 1 pick when 2 beans of same type loaded (since donot want use production profile).

2) mark beans should not loaded when profile dev active @profile("!dev") -- applicable spring 3.2 , higher (see https://github.com/spring-projects/spring-framework/commit/bcd44f3798ed06c0704d2a3564b8a9735e747e87).

or...

3) use production profile , activate in example web.xml file (something don't use locally).

simply create multiple @configuration classes , mark entire class profile (it helps keep related stuff together). typical example database. create 1 configuration class production database (something jndi , oracle) , 1 local development , testing (hsqldb).

you mark jndi configuration class @profile("production") , other @profile("dev") -- no need mark individual beans, split them logically amongst 2 different @configuration classes.

this worked us, when combined integration testing.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -