title: org.xml.sax.SAXParseException: cvc-elt.1.a: Cannot find the declaration of element
body: <p>I want to use an XML file that has settings params in it and automatically associate it with the class component fields so that it is reusable as a configuration class in the future. I was basing on post: <a href="https://stackoverflow.com/questions/49903276/how-to-read-a-property-in-the-an-xml-properties-file-in-spring-boot">click</a>.</p>
  
  <p>My file configuration.xml file looks like:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;config&gt;
    &lt;server serverport="1111"/&gt;
    &lt;client clientport="1111"&gt;
      &lt;ServerHost&gt;localhost&lt;/ServerHost&gt;
    &lt;/client&gt;
  &lt;/config&gt;
  </code></pre>
  
  <p>My classes are as follows:</p>
  
  <pre><code>@ImportResource(value = "classpath:configuration.xml")
  @Configuration
  @NoArgsConstructor
  @Getter
  public class Config {
    private Server server;
    private Client client;
  }
  </code></pre>
  
  <p>Client.java</p>
  
  <pre><code>@Getter
  public class Client {
    private @Value("#{clientport}") String clientPort;
    private String serverHost;
  }
  </code></pre>
  
  <p>Server.java</p>
  
  <pre><code>@Getter
  public class Server {
    private @Value("#{serverport}") String serverPort;
  }
  </code></pre>
  
  <p>pom.xml looks like:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;2.1.8.RELEASE&lt;/version&gt;
      &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
    &lt;/parent&gt;
    &lt;groupId&gt;com.Java&lt;/groupId&gt;
    &lt;artifactId&gt;advanced&lt;/artifactId&gt;
    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  
    &lt;properties&gt;
      &lt;java.version&gt;11&lt;/java.version&gt;
    &lt;/properties&gt;
  
    &lt;dependencies&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
        &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
        &lt;artifactId&gt;lombok&lt;/artifactId&gt;
        &lt;optional&gt;true&lt;/optional&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
        &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
    &lt;/dependencies&gt;
  
    &lt;build&gt;
      &lt;plugins&gt;
        &lt;plugin&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
        &lt;/plugin&gt;
      &lt;/plugins&gt;
    &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>With this approach I am receiving an error like:</p>
  
  <pre><code>Line 2 in XML document from class path resource [configuration.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 9; cvc-elt.1.a: Cannot find the declaration of element 'config'.
  </code></pre>
  
  <p>and </p>
  
  <pre><code>Caused by: org.xml.sax.SAXParseException: cvc-elt.1.a: Cannot find the declaration of element 'config'.
  </code></pre>
  
  <p>I am a little bit confused because seemingly it looks fine but I cannot find a source of this error. I will be grateful for a suggestion of how to solve this problem in my application and make it reusable as a class with configuration parameters from XML file. </p>
  
  <p>EDIT:
  If you know another approach to reach a desirable goal feel free to post it.</p>
  
  <p>EDIT2:
  I found walkaround for this problem but I hope that there will another solution which will bring a desirable effect: <a href="https://howtodoinjava.com/xml/convert-xml-to-properties/" rel="nofollow noreferrer">click</a></p>