Announcement Announcement Module
Collapse
No announcement yet.
I can not get a bean from the Spring 3.1.0.M1 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • I can not get a bean from the Spring 3.1.0.M1

    I can not read a bean from the Spring 3.1.0.M1.

    I decided to change my program. Now I am using AnnotationConfigWebApplicationContext instead to use ClassPathXmlApplicationContext. But the problem continues.

    I appreciate if you could help me.


    I use Eclipse Helios, JSF 2, TomCat 7,0, Hibernate 3.0 and Spring 3.1.0.M1 from the project Dynamic Web Project.

    Here there are java code, applicationContext.xml, web.xml and Errors messages.

    public static synchronized AnnotationConfigWebApplicationContext getSpringContext()
    {
    if (springContext == null){
    try{ //Here doesn't appear any problema. All is OK.
    springContext = new AnnotationConfigWebApplicationContext();
    springContext.refresh();
    }
    catch (Exception ex){
    ex.printStackTrace();
    }
    }
    return springContext;
    }

    // Here is shown me the error below that is impossible to read a bean,
    //because the myObjectTest is not defined, but the myObjectTest is defined.
    public static synchronized ClassTest getClassTest(){
    ClassTest objectTest =(ClassTest) getSpringContext().getBean("myObjectTest");
    return objectTest;
    }


    //configuration file:applicationContext put in the WEB-INF.
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schem...-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">



    <!-- this package 'test' is inserted into package 'src'
    This class is simple with properties code and name -->
    <bean id="myObjectTest" class="test.ClassTest">
    <constructor-arg name="code" value="01"/>
    <constructor-arg name="name" value="Régis de Oliveira Santos"/>
    </bean>

    </beans>





    //file web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="3.0"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

    <display-name>newproj</display-name>

    <context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
    </context-param>

    <context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContex t</param-name>
    <param-value>resources.application</param-value>
    </context-param>

    <context-param>
    <description>
    This parameter tells MyFaces if javascript code should be allowed in
    the rendered HTML output.
    If javascript is allowed, command_link anchors will have javascript code
    that submits the corresponding form.
    If javascript is not allowed, the state saving info and nested parameters
    will be added as url parameters.
    Default is 'true'</description>
    <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
    <param-value>true</param-value>
    </context-param>

    <context-param>
    <description>
    If true, a javascript function will be rendered that is able to restore the
    former vertical scroll on every request. Convenient feature if you have pages
    with long lists and you do not want the browser page to always jump to the top
    if you trigger a link or button action that stays on the same page.
    Default is 'false'
    </description>
    <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
    <param-value>true</param-value>
    </context-param>
    <context-param>
    <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
    <param-value>false</param-value>
    </context-param>

    <context-param>
    <description>
    If true, rendered HTML code will be formatted, so that it is 'human-readable'
    i.e. additional line separators and whitespace will be written, that do not
    influence the HTML code.
    Default is 'true'</description>
    <param-name>org.apache.myfaces.PRETTY_HTML</param-name>
    <param-value>true</param-value>
    </context-param>

    <! -- I put my file applicationContext.xml into /WEB-INF/ -->
    <context-param>
    <param-name>
    contextConfigLocation
    </param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>

    <!-- Here there aren't spaces after the word context. This name
    defining the listener-class is totally together. Only in this Preview post appear this manner. -->
    <listener>
    <listener-class>
    org.springframework.web.context.
    ContextLoaderListener

    </listener-class>
    </listener>


    <listener>
    <listener-class>
    org.apache.myfaces.webapp.
    StartupServletContextListener
    </listener-class>
    </listener>

    <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
    <welcome-file>inicio.jsp</welcome-file>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>

    </web-app>




    //Erros messages from running JUnit Test case
    org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'myObjectTest' is defined
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.getBeanDefinition(DefaultListab leBeanFactory.java:527)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getMergedLocalBeanDefinition(AbstractB eanFactory.java:1087)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:278 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.context.support.AbstractApplic ationContext.getBean(AbstractApplicationContext.ja va:1080)
    at config.SpringAccess.getClassTest(SpringAccess.java :40)
    at test.SpringAccessTest.testGetSessionFactory(Spring AccessTest.java:18)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runRefle ctiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallabl e.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExpl osively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod .evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.e valuate(RunBefores.java:28)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild( BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild( BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner. java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRu nner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentR unner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRu nner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRu nner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.ja va:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestR eference.run(JUnit4TestReference.java:49)
    at org.eclipse.jdt.internal.junit.runner.TestExecutio n.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:197)


    Thank you in advance,

    Régis de Oliveira Santos
    <Java Developer>
    (I am from Brazil)

  • #2
    Please use [ code][/code ] tags when posting code that way it remains readable.

    You are using an ApplicationContext which needs a @Configuration class and expect it to load an xml file, that isn't going to happen.

    Comment

    Working...
    X