The name "context:annotation-config" is not legal for JDOM/XML

1k Views Asked by At

How i can write this :

<context:annotation-config/>
<context:component-scan base-package="com.generator"/>

using jdom2. i tried by :

beans.addContent(new Element("context:annotation-config"));
beans.addContent(new Element("context:component-scan").setAttribute("base-package","com."+getProjectName()))

but i had this error:

The name "context:annotation-config" is not legal for JDOM/XML elements: XML name 'context:annotation-config' cannot contain the character ":".

1

There are 1 best solutions below

0
On

Create a Namespace as

Namespace nsContext = Namespace.getNamespace("context", // prefix
       "http://www.springframework.org/schema/context"); // URI

Then create your Element using new Element (String, Namespace)

beans.addContent(new Element("annotation-config", nsContext));