Announcement Announcement Module
No announcement yet.
I can not get a bean from the Spring 3.1.0.M1 Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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();
    catch (Exception ex){
    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=""

    <!-- 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"/>


    //file web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="3.0"
    xmlns:xsi="" xsi:schemaLocation="">


    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>

    <param-name>javax.servlet.jsp.jstl.fmt.localizationContex t</param-name>

    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>

    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'

    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>

    <! -- I put my file applicationContext.xml into /WEB-INF/ -->

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



    <servlet-name>Faces Servlet</servlet-name>

    <servlet-name>Faces Servlet</servlet-name>



    //Erros messages from running JUnit Test case
    org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'myObjectTest' is defined
    at istableBeanFactory.getBeanDefinition(DefaultListab
    at BeanFactory.getMergedLocalBeanDefinition(AbstractB
    at BeanFactory.doGetBean( )
    at BeanFactory.getBean(
    at ationContext.getBean(AbstractApplicationContext.ja va:1080)
    at config.SpringAccess.getClassTest( :40)
    at test.SpringAccessTest.testGetSessionFactory(Spring
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De
    at java.lang.reflect.Method.invoke(
    at org.junit.runners.model.FrameworkMethod$1.runRefle ctiveCall(
    at org.junit.internal.runners.model.ReflectiveCallabl
    at org.junit.runners.model.FrameworkMethod.invokeExpl osively(
    at org.junit.internal.runners.statements.InvokeMethod .evaluate(
    at org.junit.internal.runners.statements.RunBefores.e valuate(
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(
    at org.junit.runners.ParentRunner$ java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRu
    at org.junit.runners.ParentRunner.runChildren(ParentR
    at org.junit.runners.ParentRunner.access$000(ParentRu
    at org.junit.runners.ParentRunner$2.evaluate(ParentRu
    at va:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestR
    at org.eclipse.jdt.internal.junit.runner.TestExecutio
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(

    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.