2010-05-28 95 views
0

喜春豆,我使用Spring Security和我的配置是在數據庫:如何初始化數據庫從

<sec:http auto-config="true" entry-point-ref="casProcessingFilterEntryPoint"> 
     <sec:remember-me /> 
     <sec:session-management> 
      <sec:concurrency-control max-sessions="1" 
       error-if-maximum-exceeded="true" /> 
     </sec:session-management> 
     <sec:logout logout-success-url="${host.url}/logout/" /> 
     <sec:custom-filter ref="casAuthenticationFilter" 
      after="CAS_FILTER" /> 
     <sec:custom-filter ref="filterInvocationInterceptor" 
      before="FILTER_SECURITY_INTERCEPTOR" /> 
    </sec:http> 

${host.url}是數據庫

我怎麼能初始化?

這樣了,我這樣做:

public class SnsPropertyResourceConfigurer extends GrailsPlaceholderConfigurer{ 

    private BeanFactory beanFactory; 

    protected void loadProperties(Properties props) throws IOException { 
      setSystemPropertiesMode(2); 
      ConfigObject config = ConfigurationHolder.getConfig(); 
      if(config != null) { 
       props.putAll(config.toProperties()); 
      } 
       Properties add = addProperties(); 
       if(add != null){ 
        props.putAll(add); 

      } 
     } 

    private Properties addProperties(){ 

     InfoFetchClientRpcService infoFetchRpcService = (InfoFetchClientRpcService)beanFactory.getBean("infoFetchRpcService"); 
     Map<String, Application> apps = infoFetchRpcService.getAppInfo(); 
     Application thisApp = apps.get("sns"); 
     Application casApp = apps.get("cas"); 
     Properties props = new Properties(); 
     props.setProperty("cas.loginUrl", "11111111"); 
     props.setProperty("cas.logoutUrl", "222222222222"); 
     props.setProperty("cas.validator", casApp.getUrl()); 
     props.setProperty("cas.service",thisApp.getUrl()+"/j_spring_cas_security_check"); 
     props.setProperty("cas.defaultTargetUrl", thisApp.getSuccessUrl()); 
     props.setProperty("cas.defaultFailureUrl", thisApp.getFailureUrl()); 
     props.setProperty("cas.logout", thisApp.getLogoutUrl()); 
     props.setProperty("cas.logoutSuccessUrl", thisApp.getUrl()); 
     props.setProperty("cas.ticket.key", "sns"); 
     return props; 
    } 

    public void setBeanFactory(BeanFactory beanFactory) { 
     this.beanFactory = beanFactory; 
    } 
} 

<bean name="snsPropertyResourceConfigurer" class="com.ai.sns.init.SnsPropertyResourceConfigurer"> 
    </bean> 

,但它並不影響...

+0

爲什麼你直接繼承'GrailsPlaceholderConfigurer'而不是'PropertyPlaceholderConfigurer'? – skaffman 2010-05-28 07:48:52

+0

因爲我使用grails,而grails使用GrailsPlaceholderConfigurer – user340017 2010-05-28 08:28:08

+1

@skaffman所以在那裏。 – Andy 2011-04-28 11:50:08

回答

2

子類PropertyPlaceholderConfigurer並實現從數據庫加載。然後添加類作爲一個bean在applicationContext.xml(就好像它是常規PropertyPlaceholderConfigurer