Results 1 to 2 of 2
  1. #1
    Blue2525989 is offline Senior Member
    Join Date
    Sep 2016
    Rep Power

    Default trouble with xml file

    Hello all, So I am trying to get started with spring and found a tutorial to work through but I am having trouble getting it off the ground in the first place. I keep getting this error that pertains to the applicationContext.xml too me it seems like it cant find the right class. here is the error and the code. Thanks.

    Feb 04, 2017 12:14:27 PM org.springframework.beans.factory.xml.XmlBeanDefin itionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
    Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefin itionStoreException: Line 8 in XML document from class path resource [applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 8; columnNumber: 2; The markup in the document following the root element must be well-formed.

    Java Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <bean id="studentbean" class="Blue.Student">
    <property name="name" value="Jason Bierbrauer"></property>
    Java Code:
    package BlueWeb;
    public class Student {
    private String name;
    // simple bean class
    public String getName() {
    	return name;
    public void setName(String name) { = name;
    public void displayInfo() {
    	System.out.println("Hello: " + name);

    Java Code:
    package BlueWeb;
    import org.springframework.beans.factory.BeanFactory;
    import org.springframework.beans.factory.xml.XmlBeanFactory;
    public class Test {
    	public static void main(String[] args) {
    	Resource resource = new ClassPathResource("applicationContext.xml");
    	BeanFactory factory = new XmlBeanFactory(resource);
    	Student student = (Student)factory.getBean("studentbean");

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power

    Default Re: trouble with xml file

    At a guess your <bean> should be inside the <beans></beans> tag.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Java save to file / open from file - trouble
    By joelBeaton in forum Advanced Java
    Replies: 6
    Last Post: 03-23-2012, 01:47 PM
  2. Trouble executing a file!
    By javabeginner29 in forum New To Java
    Replies: 1
    Last Post: 02-26-2012, 10:29 AM
  3. trouble inporting from a file
    By mnorman in forum New To Java
    Replies: 12
    Last Post: 12-11-2011, 08:24 PM
  4. trouble with FILE I/O
    By dru36 in forum New To Java
    Replies: 27
    Last Post: 12-02-2011, 10:25 PM
  5. Log file trouble
    By kovalensue in forum Advanced Java
    Replies: 3
    Last Post: 04-03-2011, 06:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts