简体   繁体   中英

how to initialize spring bean from database

hi,i use spring security and my config is in database:

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

like ${host.url} is in database

how can i initialize ?

so,and i do this :

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;
    }
}

and

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

but it not effect...

Subclass PropertyPlaceholderConfigurer and implement the loading from database. Then add that class as a bean in applicationContext.xml (as if it was the regular PropertyPlaceholderConfigurer )

i resolve this problem。。。

i register placeholderConfigurer in main application context where is web-app/WEB-INF/applicationContext.xml but not grails-app/conf/spring/resources.xml it works well

thk for everyone

quote: http://jira.codehaus.org/browse/GRAILS-1958?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#issue-tabs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM