IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Java Discussion :

[OSGi] Problème d'instanciation de l'applicationContext [Framework]


Sujet :

Spring Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Novembre 2006
    Messages
    17
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 17
    Par défaut [OSGi] Problème d'instanciation de l'applicationContext
    Bonjour tout le monde,

    merci d'avance pour l'aide que vous pourrez m'apporter.

    Voici mon problème.

    Je compte dans un bundle OSGI faire une simple instanciation d'un bean depuis mon application Context.

    J'ai une classe java :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    package testspring;
     
    public class ClassIOC {
     
    	public void helloWorld(){
    		System.out.println("Hello World Spring with OSGI");
    	}
     
    }
    J'ai mon activator :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
     
    package testspring;
     
    import org.osgi.framework.BundleActivator;
    import org.osgi.framework.BundleContext;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
     
    public class Activator implements BundleActivator {
     
    	private static BundleContext context;
     
    	static BundleContext getContext() {
    		return context;
    	}
     
    	/*
    	 * (non-Javadoc)
    	 * 
    	 * @see
    	 * org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext
    	 * )
    	 */
    	public void start(BundleContext bundleContext) throws Exception {
    	Activator.context = bundleContext;
     
    		ApplicationContext appContext = new ClassPathXmlApplicationContext(
    				"META-INF/spring/applicationContext.xml");
    		ClassIOC instance = (ClassIOC) appContext.getBean("ClassIOC");
    		instance.helloWorld();
     
    	}
     
    	/*
    	 * (non-Javadoc)
    	 * 
    	 * @see
    	 * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
    	 */
    	public void stop(BundleContext bundleContext) throws Exception {
    		Activator.context = null;
    	}
     
    }
    J'ai mon projet manifest comme ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
     
    Manifest-Version: 1.0
    Bundle-ManifestVersion: 2
    Bundle-Name: TestSpring
    Bundle-SymbolicName: TestSpring
    Bundle-Version: 1.0.0.qualifier
    Bundle-Activator: testspring.Activator
    Bundle-ActivationPolicy: lazy
    Bundle-RequiredExecutionEnvironment: JavaSE-1.6
    Import-Package: org.osgi.framework;version="1.3.0"
    Bundle-ClassPath: .
    Require-Bundle: org.springframework.aop;bundle-version="2.5.6",
     org.springframework.beans;bundle-version="2.5.6",
     org.springframework.context;bundle-version="2.5.6",
     org.springframework.core;bundle-version="2.5.6",
     com.springsource.org.apache.commons.logging;bundle-version="1.1.1",
     com.springsource.org.apache.log4j;bundle-version="1.2.15"
    Dans mon conteneur OSGI, j'ai bien tous les bundles qu'il faut.

    Et à chaque activation de mon bundle, j'ai le droit à l'exception suivante :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
     
    org.osgi.framework.BundleException: Activator start error in bundle TestSpring [36].
            at org.apache.felix.framework.Felix.activateBundle(Felix.java:1869)
            at org.apache.felix.framework.Felix.startBundle(Felix.java:1739)
            at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:922)
            at org.apache.felix.gogo.command.Basic.start(Basic.java:758)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.apache.felix.gogo.runtime.Reflective.method(Reflective.java:136)
            at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:82)
            at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:458)
            at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:384)
            at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
            at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:183)
            at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:120)
            at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:79)
            at org.apache.felix.gogo.shell.Console.run(Console.java:62)
            at org.apache.felix.gogo.shell.Shell.console(Shell.java:198)
            at org.apache.felix.gogo.shell.Shell.gosh(Shell.java:124)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.apache.felix.gogo.runtime.Reflective.method(Reflective.java:136)
            at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:82)
            at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:458)
            at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:384)
            at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
            at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:183)
            at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:120)
            at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:79)
            at org.apache.felix.gogo.shell.Activator.run(Activator.java:75)
            at java.lang.Thread.run(Unknown Source)
    Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [META-I
    NF/spring/applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [META-INF/spring/applicationContex
    t.xml] cannot be opened because it does not exist
            at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:349)
            at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
            at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
     
            at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
     
            at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
     
            at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
     
            at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:113)
            at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:80)
            at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContex
    t.java:123)
            at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:422)
            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
            at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
            at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
            at testspring.Activator.start(Activator.java:31)
            at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:633)
            at org.apache.felix.framework.Felix.activateBundle(Felix.java:1822)
            ... 32 more
    Caused by: java.io.FileNotFoundException: class path resource [META-INF/spring/applicationContext.xml] cannot be opened because it does not
    exist
            at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:143)
            at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
            ... 47 more
    org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [META-INF/spring/a
    pplicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [META-INF/spring/applicationContext.xml] cann
    ot be opened because it does not exist
    j'ai essayé de délcarer le répertoire META-INF/spring comme source, j'ai essayer d'accéder à mon application contexte directement (sans le "META-INF/spring"), et ça ne change rien !

    Si j'ajoute les jar en tant que librairie de mon projet alors là ça marche....

    Je suis un peu à cours d'idée pour faire fonctionner cela. Car ce que je veux faire c'est une bête instanciation de bean, je ne veux pas utiliser pour le moment spring dm....

    Ou alors suis-je obligé ?

    Si vous avez des idées, je suis preneur, car là ça fait 2 jours que je perds sur cette *** "!@$. bref

    merci d'avance.

  2. #2
    Membre averti
    Inscrit en
    Novembre 2006
    Messages
    17
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 17
    Par défaut
    Bon finallement, j'ai trouver la réponse.

    En gros avec OSGI c'est pas conseillé d'accéder à son application contexte pour faire de l'instanciation il est préférable d'exposer ses beans en tant que service. Mais il est possible sinon d'accéder à son application contexte avec l'instruction suivante :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    ServiceReference webContext = context.getAllServiceReferences("org.springframework.context.ApplicationContext", "(org.springframework.context.service.name=com.binomed.osgi.spring.test)")[0];
    où com.binomed.osgi.spring.test est l'id de mon bundle

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [C#][Architecture] Problème d'instanciation
    Par loic_86 dans le forum C#
    Réponses: 1
    Dernier message: 06/03/2007, 14h59
  2. [JSP-Bean] Probléme d'instanciation d'une classe !
    Par adil_vpb dans le forum Servlets/JSP
    Réponses: 5
    Dernier message: 02/03/2007, 19h29
  3. Problème d'instanciation d'une classe
    Par Jahjouh dans le forum C++
    Réponses: 2
    Dernier message: 03/02/2007, 12h50
  4. Réponses: 7
    Dernier message: 18/07/2006, 12h23
  5. problème pour instancier une class
    Par gronaze dans le forum C++
    Réponses: 8
    Dernier message: 30/06/2006, 12h21

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo