Writing D:/inetpub/webs/vincenzodevivocom/wiki/data/cache/2/27f98dfc1e4e3befd955901070b5c577.i failed
Unable to save cache file. Hint: disk full; file permissions; safe_mode setting.
Writing D:/inetpub/webs/vincenzodevivocom/wiki/data/cache/2/27f98dfc1e4e3befd955901070b5c577.i failed
Unable to save cache file. Hint: disk full; file permissions; safe_mode setting.
Writing D:/inetpub/webs/vincenzodevivocom/wiki/data/cache/2/27f98dfc1e4e3befd955901070b5c577.xhtml failed

Spring

Richiamare un metodo di una classe mediante bean spring e ottenere un valore per poi usarlo in un altro bean

test.xml
<bean id="connection.url" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
   <property name="targetClass"><value>com.vincenzodevivo.Config</value></property>
   <property name="targetMethod"><value>getProperty</value></property>
   <property name="arguments">
	 <list>
	   <value>connection.url</value>
	 </list>
   </property>
</bean>
 
<bean id="test" class="com.vincenzodevivo.Test">
   <property name="url" ref="connection.url"/>
</bean>

Come accedere allo Spring-ApplicationContext da qualsiasi parte dell'applicazione

Access the Spring-ApplicationContext from everywhere in your Application

ApplicationContextProvider.java
package context;
 
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
 
/**
 * This class provides an application-wide access to the
 * Spring ApplicationContext! The ApplicationContext is
 * injected in a static method of the class "AppContext".
 *
 * Use AppContext.getApplicationContext() to get access
 * to all Spring Beans.
 *
 */
public class ApplicationContextProvider implements ApplicationContextAware {
 
    public void setApplicationContext(ApplicationContext ctx) throws BeansException {
        // Wiring the ApplicationContext into a static method
        AppContext.setApplicationContext(ctx);
    }
} // .EOF
applicationContext.xml
<bean id="contextApplicationContextProvider" class="context.ApplicationContextProvider"></bean>
AppContext.java
package context;
 
import org.springframework.context.ApplicationContext;
 
/**
 * This class provides application-wide access to the Spring ApplicationContext.
 * The ApplicationContext is injected by the class "ApplicationContextProvider".
 *
 */
public class AppContext {
 
    private static ApplicationContext ctx;
 
    /**
     * Injected from the class "ApplicationContextProvider" which is automatically
     * loaded during Spring-Initialization.
     */
    public static void setApplicationContext(ApplicationContext applicationContext) {
        ctx = applicationContext;
    }
 
    /**
     * Get access to the Spring ApplicationContext from everywhere in your Application.
     *
     * @return
     */
    public static ApplicationContext getApplicationContext() {
        return ctx;
    }
} // .EOF

Ora puoi accedere da tutte le classi allo Spring-ApplicationContext della tua applicazione chiamando il metodo statico:

Poorfile.java
ApplicationContext ctx = AppContext.getApplicationContext();
Honeypotbean honey = (HoneyPotBean) ctx.getBean("honey");

Loading xml inside a jar file

String xml = IOUtils.toString(new PathMatchingResourcePatternResolver().findPathMatchingResources(folder+"*.xml")[0].getURI().toURL().openStream());
 
code/java/spring.txt · Last modified: 2014/09/17 16:46 by Vincenzo De Vivo
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki