wyona / yanel

http://www.yanel.org
Apache License 2.0
10 stars 5 forks source link

Yanel.getInstance().init() is still broken #7

Open baszero opened 12 years ago

baszero commented 12 years ago

Hi, this is a followup on #6:

as I do not have permissions to reopen an issue, I create a new one:

I just tested Yanel "standalone" in the latest version (3469f949063fab13b1dafc9a45921e689047a157) and I still get this error:


180 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory  - No bean named 'map' found in org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans []; root of BeanFactory hierarchy
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'map' is defined
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:355)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:800)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:237)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:642)
    at org.wyona.yanel.core.Yanel.init(Yanel.java:81)
    at test.Test.run32(Test.java:92)
    at test.Test.main(Test.java:86)
michaelwechner commented 12 years ago

It works for me

run-yanel-cmdl: [echo] Yanel Path: [java] Welcome to the Yanel command line interface! [java] [java] Loading realms and resources/controllers... (please be patient) [java] [java] The following realms have been configured:

......

 [java] Please enter a path (e.g. /index.html):

 [java] No path has been specified!

BUILD SUCCESSFUL

Total time: 22 seconds

Is it possible that you have some local changes or that your realm contains libs which cannot be loaded for some reason?

Can you give it a try with a clean Yanel (without any third party realms)?

Thanks

baszero commented 12 years ago

When I try yanel.sh cmdl it works fine.

So I guess it is a classpath problem, but I do not understand why from the realm's point of view one should take care of this, adding the Yanel libs should be sufficient in order to make it work.

The error is obviously in the Yanel() constructor where the Spring config file gets loaded. Somehow that file can not be found on the classpath because the map is not known (map is configured in spring-yanel-config.xml).

It would be interesting what is needed exactly on the classpath to make it work, e.g. what classpath does the CMDL have?

michaelwechner commented 12 years ago

Am 14.11.11 16:08, schrieb baszero:

When I try yanel.sh cmdl it works fine.

So I guess it is a classpath problem, but I do not understand why from the realm's point of view one should take care of this, adding the Yanel libs should be sufficient in order to make it work.

The error is obviously in the Yanel() constructor where the Spring config file gets loaded. Somehow that file can not be found on the classpath because the map is not known (map is configured in spring-yanel-config.xml).

It would be interesting what is needed exactly on the classpath to make it work, e.g. what classpath does the CMDL have?

see src/build/targets/cmdl.xml (and search for DEBUG)

HTH

Michael


Reply to this email directly or view it on GitHub: https://github.com/wyona/yanel/issues/7#issuecomment-2731412

baszero commented 12 years ago

Hi Michael,

I wrote a little Test class where in the main() method you can choose between two tests:

The difference of the two tests is only the definition of the Yanel.SPRING_CONFIG_FILE String.

All would work fine if the Yanel.SPRING_CONFIG_FILE would be changed. I don't know yet why exactly this is the case but I'm sure it has something to do how files are loaded by the classloader.

Here is the full Test class:

package test;

import java.io.InputStream;

import org.apache.log4j.BasicConfigurator;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.wyona.yanel.core.Yanel;
import org.wyona.yanel.core.map.Map;

public class Test2 {

    public static void main(String[] args) {
        BasicConfigurator.configure();
        Test2 test = new Test2();
        test.doesNotWork();
    }

    public void doesNotWork() {
        try {
            // This is the string how it is configured in Yanel.SPRING_CONFIG_FILE :
            String path = "spring-*-config.xml"; // does not work
            test(path);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void worksFine() {
        try {
            String path = "/spring-yanel-config.xml"; // working fine!
            test(path);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void test(String path) {
        try {
            InputStream stream = Test2.class.getResourceAsStream(path);
            System.out.println(stream!=null);

            ApplicationContext applicationContext = new ClassPathXmlApplicationContext(path);
            System.out.println(applicationContext!=null);

            Yanel yanel = Yanel.getInstance();
            System.out.println(yanel!=null);

            // The following line is from Yanel.init():
            Map map = (Map) applicationContext.getBean("map");
            System.out.println(map!=null);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

The output of the not-working example is the same as I get when running Yanel in standalone:

false
true
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'map' is defined
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:355)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:800)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:237)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:642)
    at test.Test2.test(Test2.java:56)
    at test.Test2.doesNotWork(Test2.java:27)
    at test.Test2.main(Test2.java:20)
true