Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

spring example errors

Hi,,

I am trying below spring example at bottom of page

http://www.tutorialspoint.com/spring/spring_autowired_annotation.htm

I am seeing attached errors.

how to resolve them.

i added attached jars still issue not fixed.

this is non maven ecample so i have to download manually jars without conflict.

how to converyt it to maven application?

error description is as below

Description      Resource      Path      Location      Type
The type org.springframework.beans.BeansException cannot be resolved. It is indirectly referenced from required .class files      MainApp.java      /SpringAutoWire/src      line 6      Java Problem
The project was not built since its build path is incomplete. Cannot find the class file for org.springframework.beans.BeansException. Fix the build path then try building this project      SpringAutoWire            Unknown      Java Problem

please advise.

Go i need spring 2.5 jar or spring 3 or spring 4 jar?

where i can download all the right jars with corrcet versioning.
errorsAll.png
errorsAllJArs.png
Avatar of gudii9
gudii9
Flag of United States of America image

ASKER

when i put spring 2.5 jar those errors are gone

http://www.java2s.com/Code/Jar/s/Downloadspring25jar.htm

but when i run MainApp.java gettign below error.

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainApp {
   public static void main(String[] args) {
      ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");

      Profile profile = (Profile) context.getBean("profile");

      profile.printAge();
      profile.printName();
   }
}

Open in new window


please advise
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/beans/factory/config/BeanExpressionResolver
      at MainApp.main(MainApp.java:6)
Caused by: java.lang.ClassNotFoundException: org.springframework.beans.factory.config.BeanExpressionResolver
      at java.net.URLClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      ... 1 more
Avatar of gudii9

ASKER

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainApp {
   public static void main(String[] args) {
      ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");

      Profile profile = (Profile) context.getBean("profile");

      profile.printAge();
      profile.printName();
   }
}

Open in new window


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

public class Profile {
   @Autowired
   @Qualifier("student1")
   private Student student;

   public Profile(){
      System.out.println("Inside Profile constructor." );
   }

   public void printAge() {
      System.out.println("Age : " + student.getAge() );
   }

   public void printName() {
      System.out.println("Name : " + student.getName() );
   }
}

Open in new window

public class SpellChecker {
   public SpellChecker(){
      System.out.println("Inside SpellChecker constructor." );
   }

   public void checkSpelling(){
      System.out.println("Inside checkSpelling." );
   }
   
}

Open in new window

public class Student {
   private Integer age;
   private String name;

   public void setAge(Integer age) {
      this.age = age;
   }
   
   public Integer getAge() {
      return age;
   }

   public void setName(String name) {
      this.name = name;
   }
   
   public String getName() {
      return name;
   }
}

Open in new window


 	 	public class TextEditor {
   private SpellChecker spellChecker;

   @Autowired
   public void setSpellChecker( SpellChecker spellChecker ){
      this.spellChecker = spellChecker;
   }
   public SpellChecker getSpellChecker( ) {
      return spellChecker;
   }
   public void spellCheck() {
      spellChecker.checkSpelling();
   }
}

Open in new window


my code looks as above
Avatar of gudii9

ASKER

<?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/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">

   <context:annotation-config/>

   <!-- Definition for profile bean -->
   <bean id="profile" class="Profile">
   </bean>S

   <!-- Definition for student1 bean -->
   <bean id="student1" class="Student">
      <property name="name"  value="Zara" />
      <property name="age"  value="11"/>
   </bean>

   <!-- Definition for student2 bean -->
   <bean id="student2" class="com.tutorialspoint.Student">
      <property name="name"  value="Nuha" />
      <property name="age"  value="2"/>
   </bean>

</beans>

Open in new window


i changed Beans.xml as above by removing package structure
still getting below error
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/beans/factory/config/BeanExpressionResolver
      at MainApp.main(MainApp.java:6)
Caused by: java.lang.ClassNotFoundException: org.springframework.beans.factory.config.BeanExpressionResolver
      at java.net.URLClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      ... 1 more



i see in BEans.xml some kind of warning as below


cvc-complex-type.2.3: Element 'beans' cannot have character [children], because the type's content type is element-only.
You need Spring-beans.jar on your path too.
Suggest you add that as a dependency in your pom.xml.
Avatar of gudii9

ASKER

<?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/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">

   <context:annotation-config/>

   <!-- Definition for profile bean -->
   <bean id="profile" class="Profile">
   </bean>

   <!-- Definition for student1 bean -->
   <bean id="student1" class="Student">
      <property name="name"  value="Zara" />
      <property name="age"  value="11"/>
   </bean>

   <!-- Definition for student2 bean -->
   <bean id="student2" class="com.tutorialspoint.Student">
      <property name="name"  value="Nuha" />
      <property name="age"  value="2"/>
   </bean>

</beans>

Open in new window


fixed Beans.xml by removing extra S chanracter

when i run below class

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainApp {
   public static void main(String[] args) {
      ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");

      Profile profile = (Profile) context.getBean("profile");

      profile.printAge();
      profile.printName();
   }
}

Open in new window


Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/beans/factory/config/BeanExpressionResolver
      at MainApp.main(MainApp.java:6)
Caused by: java.lang.ClassNotFoundException: org.springframework.beans.factory.config.BeanExpressionResolver
      at java.net.URLClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      ... 1 more

getting above error
Avatar of gudii9

ASKER

i added spring beans jar

http://java2s.com/Code/Jar/s/Downloadspringbeansjar.htm

still getting same error

Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/beans/factory/config/BeanExpressionResolver
      at MainApp.main(MainApp.java:6)
Caused by: java.lang.ClassNotFoundException: org.springframework.beans.factory.config.BeanExpressionResolver
      at java.net.URLClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      ... 1 more
Avatar of gudii9

ASKER

i downloaded and set buildpath with spring bean 2.5
http://www.java2s.com/Code/Jar/s/Downloadspringbeans25jar.htm

My final jars looks as attached



Jun 12, 2016 10:13:55 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@27d6c5e0: display name [org.springframework.context.support.ClassPathXmlApplicationContext@27d6c5e0]; startup date [Sun Jun 12 22:13:54 EDT 2016]; root of context hierarchy
Jun 12, 2016 10:13:55 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [Beans.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [Beans.xml]; nested exception is java.lang.IllegalStateException: Context namespace element 'annotation-config' and its parser class [org.springframework.context.annotation.AnnotationConfigBeanDefinitionParser] are only available on JDK 1.5 and higher
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:385)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:313)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:290)
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:142)
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:158)
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:184)
      at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:112)
      at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:79)
      at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:97)
      at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:411)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:338)
      at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:122)
      at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66)
      at MainApp.main(MainApp.java:6)
Caused by: java.lang.IllegalStateException: Context namespace element 'annotation-config' and its parser class [org.springframework.context.annotation.AnnotationConfigBeanDefinitionParser] are only available on JDK 1.5 and higher
      at org.springframework.context.config.ContextNamespaceHandler$1.parse(ContextNamespaceHandler.java:64)
      at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:69)
      at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1246)
      at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1236)
      at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:133)
      at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:90)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:468)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:363)
      ... 13 more
finalJArs.png
a classic guddi9 goose chase!

can you confirm that adding the spring-beans jar fixed the original problem?
the above stack trace is to do with your application-context file containing invalid xml.
Avatar of gudii9

ASKER

spring-beans jar fixed the original problem?

it did fixed.

the above stack trace is to do with your application-context file containing invalid xml.

<?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/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">

   <context:annotation-config/>

   <!-- Definition for profile bean -->
   <bean id="profile" class="Profile">
   </bean>

   <!-- Definition for student1 bean -->
   <bean id="student1" class="Student">
      <property name="name"  value="Zara" />
      <property name="age"  value="11"/>
   </bean>

   <!-- Definition for student2 bean -->
   <bean id="student2" class="com.tutorialspoint.Student">
      <property name="name"  value="Nuha" />
      <property name="age"  value="2"/>
   </bean>

</beans>

Open in new window

not sure what is issue with above Beans.xml
Avatar of gudii9

ASKER

spring-beans jar fixed the original problem?

it did fixed.

the above stack trace is to do with your application-context file containing invalid xml.

<?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/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">

   <context:annotation-config/>

   <!-- Definition for profile bean -->
   <bean id="profile" class="Profile">
   </bean>

   <!-- Definition for student1 bean -->
   <bean id="student1" class="Student">
      <property name="name"  value="Zara" />
      <property name="age"  value="11"/>
   </bean>

   <!-- Definition for student2 bean -->
   <bean id="student2" class="com.tutorialspoint.Student">
      <property name="name"  value="Nuha" />
      <property name="age"  value="2"/>
   </bean>

</beans>

Open in new window

not sure what is issue with above Beans.xml
The error message is quite clear if you read it.

<context:annotation-config/>

You can't use this since it has indicated you are running in a JVM < 1.5
Avatar of gudii9

ASKER

i thought i have 1.8 which is what command line says when i type

C:\Users\zzz>java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b15, mixed mode)
how to check what jdk eclipse pointing and how to to change foerever to 1.8 for all future projects as well?
Avatar of gudii9

ASKER

as attached build path shows 1.8 as JRE when i right click on my project and buildpath
You can't use Spring 2.5 with Java 1.8
Please upgrade your spring distribution.
Avatar of gudii9

ASKER

when i search on google spring 3.0 jar i get below link

http://mvnrepository.com/artifact/org.springframework/spring-web/3.0.5.RELEASE

spring 3.0 jar is same as spring-web jar?
please confirm?
Avatar of gudii9

ASKER

http://mvnrepository.com/artifact/org.springframework/spring-beans/3.0.4.RELEASE
i see above fine?

3.0.5 for spring
3.0.4 for spring bean?
subversion i mean?
Avatar of gudii9

ASKER

spring 3bjats not recognizing spring context, context, appliaction context, classpath context etc


Jun 13, 2016 3:44:00 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@27d6c5e0: display name [org.springframework.context.support.ClassPathXmlApplicationContext@27d6c5e0]; startup date [Mon Jun 13 15:44:00 EDT 2016]; root of context hierarchy
Jun 13, 2016 3:44:00 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [Beans.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [Beans.xml]; nested exception is java.lang.IllegalStateException: Context namespace element 'annotation-config' and its parser class [org.springframework.context.annotation.AnnotationConfigBeanDefinitionParser] are only available on JDK 1.5 and higher
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:385)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:313)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:290)
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:142)
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:158)
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:184)
      at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:112)
      at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:79)
      at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:97)
      at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:411)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:338)
      at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:122)
      at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66)
      at MainApp.main(MainApp.java:6)
Caused by: java.lang.IllegalStateException: Context namespace element 'annotation-config' and its parser class [org.springframework.context.annotation.AnnotationConfigBeanDefinitionParser] are only available on JDK 1.5 and higher
      at org.springframework.context.config.ContextNamespaceHandler$1.parse(ContextNamespaceHandler.java:64)
      at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:69)
      at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1246)
      at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1236)
      at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:133)
      at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:90)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:468)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:363)
      ... 13 more
4.3 is the latest version of spring. why don't you use the latest?
Avatar of gudii9

ASKER

i am confused with spring versions after trying 4 days. for simple helloworld example so many trials which i cannot believe. I wonder if you were able to run this example successfully on your machine
Avatar of gudii9

ASKER

Description      Resource      Path      Location      Type
ApplicationContext cannot be resolved to a type      MainApp.java      /SpringAutoWire/src      line 6      Java Problem
Autowired cannot be resolved to a type      TextEditor.java      /SpringAutoWire/src      line 4      Java Problem
ClassPathXmlApplicationContext cannot be resolved to a type      MainApp.java      /SpringAutoWire/src      line 6      Java Problem
The import org.springframework.context cannot be resolved      MainApp.java      /SpringAutoWire/src      line 1      Java Problem
The import org.springframework.context cannot be resolved      MainApp.java      /SpringAutoWire/src      line 2      Java Problem

above is latest error which should work with spring 3 right? not sure how spring 4 fix above issues?
Avatar of gudii9

ASKER

http://stackoverflow.com/questions/12084265/spring-applicationcontext-cannot-be-resolved-even-with-jar

followed above cool link and put spring context 3.0.3 jar and resolved all errors except autowire which i am figuring out now which of spring 3 has that class
glad to hear.
Avatar of gudii9

ASKER

now i see below errror

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
      at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:154)
      at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:215)
      at org.springframework.context.support.AbstractRefreshableApplicationContext.<init>(AbstractRefreshableApplicationContext.java:88)
      at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.<init>(AbstractRefreshableConfigApplicationContext.java:58)
      at org.springframework.context.support.AbstractXmlApplicationContext.<init>(AbstractXmlApplicationContext.java:61)
      at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:136)
      at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
      at MainApp.main(MainApp.java:6)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
      at java.net.URLClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      ... 8 more
ASKER CERTIFIED SOLUTION
Avatar of gurpsbassi
gurpsbassi
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gudii9

ASKER

oh let me try
Avatar of gudii9

ASKER

now i get real eror

Jun 14, 2016 4:47:10 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@2077d4de: startup date [Tue Jun 14 16:47:10 EDT 2016]; root of context hierarchy
Jun 14, 2016 4:47:10 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [Beans.xml]
Inside Profile constructor.
Jun 14, 2016 4:47:11 PM org.springframework.context.support.AbstractApplicationContext refresh
WARNING: Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'profile': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private Student Profile.student; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.tutorialspoint.Student] for bean with name 'student2' defined in class path resource [Beans.xml]; nested exception is java.lang.ClassNotFoundException: com.tutorialspoint.Student
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
      at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
      at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
      at MainApp.main(MainApp.java:6)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private Student Profile.student; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.tutorialspoint.Student] for bean with name 'student2' defined in class path resource [Beans.xml]; nested exception is java.lang.ClassNotFoundException: com.tutorialspoint.Student
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
      at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
      ... 13 more
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.tutorialspoint.Student] for bean with name 'student2' defined in class path resource [Beans.xml]; nested exception is java.lang.ClassNotFoundException: com.tutorialspoint.Student
      at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1328)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:622)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:591)
      at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1397)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:434)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:412)
      at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:186)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1105)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
      ... 15 more
Caused by: java.lang.ClassNotFoundException: com.tutorialspoint.Student
      at java.net.URLClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at org.springframework.util.ClassUtils.forName(ClassUtils.java:249)
      at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1349)
      at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1320)
      ... 25 more

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'profile': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private Student Profile.student; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.tutorialspoint.Student] for bean with name 'student2' defined in class path resource [Beans.xml]; nested exception is java.lang.ClassNotFoundException: com.tutorialspoint.Student
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
      at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
      at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
      at MainApp.main(MainApp.java:6)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private Student Profile.student; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.tutorialspoint.Student] for bean with name 'student2' defined in class path resource [Beans.xml]; nested exception is java.lang.ClassNotFoundException: com.tutorialspoint.Student
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
      at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
      ... 13 more
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.tutorialspoint.Student] for bean with name 'student2' defined in class path resource [Beans.xml]; nested exception is java.lang.ClassNotFoundException: com.tutorialspoint.Student
      at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1328)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:622)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:591)
      at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1397)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:434)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:412)
      at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:186)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1105)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
      ... 15 more
Caused by: java.lang.ClassNotFoundException: com.tutorialspoint.Student
      at java.net.URLClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at org.springframework.util.ClassUtils.forName(ClassUtils.java:249)
      at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1349)
      at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1320)
      ... 25 more

which i am happy to see.
how to resolve this actual error..
some package path issue
Avatar of gudii9

ASKER

yahoo..i see output

Jun 14, 2016 4:49:14 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@2077d4de: startup date [Tue Jun 14 16:49:14 EDT 2016]; root of context hierarchy
Jun 14, 2016 4:49:14 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [Beans.xml]
Inside Profile constructor.
Age : 11
Name : Zara


next time how to do this kind of example in 4 minutes not 4 days.

any feed back is appreciated on my approach to improve?
feedback = learn how to use maven and understand what dependancy management is all about.
Avatar of gudii9

ASKER

i have one feedback to me.
i do not read error messages as attentively as you all do and understand gist of it which i should improve.

any tips on reading error logs better like bottom up or top down or left right etc esp log is thousands of lines and classes involved many hundreds?
read up on java stack stack traces.
Avatar of gudii9

ASKER

sure