{"id":3592,"date":"2011-07-07T13:31:10","date_gmt":"2011-07-07T11:31:10","guid":{"rendered":"http:\/\/blog.jteam.nl\/2011\/07\/07\/enhancing-ide-support-for-custom-spring-namespace-elements\/"},"modified":"2011-07-07T13:31:10","modified_gmt":"2011-07-07T11:31:10","slug":"enhancing-ide-support-for-custom-spring-namespace-elements","status":"publish","type":"post","link":"https:\/\/trifork.nl\/blog\/enhancing-ide-support-for-custom-spring-namespace-elements\/","title":{"rendered":"Enhancing IDE support for custom Spring Namespace elements"},"content":{"rendered":"<p>Spring offers many namespaces for the XML Application Context configuration to make your life a lot easier. Although not often needed, it is easy to create your own namespaces and provide custom elements. It makes configuration easier. However, I noticed that the some of the IDE support is lost. By chance, I found an undocumented feature that resolves this issue.<\/p>\n<p><!--more--><\/p>\n<h2>Spring namespace support<\/h2>\n<p>If you have ever configured Spring AOP aspects using plain bean definitions, you should know how powerful Spring Namespace support is. Instead of wiring lots of beans, just one or two elements take its place.<\/p>\n<p>If you want to create your own namespaces for a Spring Context, you\u2019ll find yourself creating an XSD file, a <code>NamespaceHandler<\/code> and <code>BeanDefinitionParser<\/code>s. Sounds complicated, but all there is to it is translating the XML in an application context into a <code>BeanDefinition<\/code>.<\/p>\n<p>But that\u2019s not what I want to dive into in this article. Spring has documented it pretty well in its reference documentation. It\u2019s what happens in my IDE (IntelliJ, but similar stuff probably happens in Eclipse and SpringSource Tool Suite) that made me look for a solution.<\/p>\n<p><a href=\"http:\/\/blog.jteam.nl\/wp-content\/uploads\/2011\/07\/unparsed_custom_bean.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none;border-right-width: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px;padding-top: 0px\" title=\"unparsed_custom_bean\" border=\"0\" alt=\"unparsed_custom_bean\" src=\"http:\/\/blog.jteam.nl\/wp-content\/uploads\/2011\/07\/unparsed_custom_bean_thumb.png\" width=\"559\" height=\"365\" \/><\/a><\/p>\n<p>First of all, the IDE starts warning me about \u201cCustom Spring Beans\u201d not being parsed. There is a quick fix for it, but it pops back as soon as any changes are made. It\u2019s just a warning, everything will work fine at runtime. But annoying nonetheless.<\/p>\n<p>But even more annoying is that the IDE doesn\u2019t help me check whether references to other beans exist or are of the correct type. It does to for other beans, why not for mine?<\/p>\n<h2>The tool namespace<\/h2>\n<p>When browsing my way through one of Spring\u2019s own XSD\u2019s, I accidentally stumbled upon the tool namespace (<a title=\"http:\/\/www.springframework.org\/schema\/tool\" href=\"http:\/\/www.springframework.org\/schema\/tool\">http:\/\/www.springframework.org\/schema\/tool<\/a>). At first, I assumed that it was just another namespace. But it seemed to be used in a completely different way.<\/p>\n<p>The namespace was used inside the XSD:<\/p>\n<p><a href=\"http:\/\/blog.jteam.nl\/wp-content\/uploads\/2011\/07\/tool_namespace.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none;border-right-width: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px;padding-top: 0px\" title=\"tool_namespace\" border=\"0\" alt=\"tool_namespace\" src=\"http:\/\/blog.jteam.nl\/wp-content\/uploads\/2011\/07\/tool_namespace_thumb.png\" width=\"662\" height=\"269\" \/><\/a><\/p>\n<p>The <code>xsd:appinfo <\/code>element is used to provide information to applications parsing the XSD. It may contain any number and type of elements.<\/p>\n<p>I took my chances and started adding the <code>tool:annotation<\/code> elements in my XSD. Two of the elements in the tool namespace are particularly useful.<\/p>\n<p>When an attribute represents a reference to a bean of a certain type, you use the following structure:<\/p>\n<pre>\n&lt;xsd:attribute name=&quot;myattribute&quot; use=&quot;optional&quot; type=&quot;xsd:string&quot;&gt;\n    &lt;xsd:annotation&gt;\n        &lt;xsd:appinfo&gt;\n            &lt;tool:annotation kind=&quot;ref&quot;&gt;\n                &lt;tool:expected-type type=&quot;expected.type.of.Bean&quot; \/&gt;\n            &lt;\/tool:annotation&gt;\n        &lt;\/xsd:appinfo&gt;\n    &lt;\/xsd:annotation&gt;\n&lt;\/xsd:attribute&gt;\n<\/pre>\n<p>When a custom element produces a bean of a certain type, you can tell the IDE as follows:<\/p>\n<pre>\n&lt;xsd:element name=&quot;MyElement&quot;&gt;\n    &lt;xsd:annotation&gt;\n        &lt;xsd:appinfo&gt;\n            &lt;tool:annotation&gt;\n                &lt;tool:exports type=&quot;fully.qualified.ClassName&quot; \/&gt;\n            &lt;\/tool:annotation&gt;\n        &lt;\/xsd:appinfo&gt;\n    &lt;\/xsd:annotation&gt;\n    &lt;!-- Acutal element definition here --&gt;\n&lt;\/xsd:element&gt;\n<\/pre>\n<p>You can repeat the <code>tool:exports<\/code> element if an element produces more than one bean.<\/p>\n<p>You can probably guess the result:<\/p>\n<p><a href=\"http:\/\/blog.jteam.nl\/wp-content\/uploads\/2011\/07\/parsed_custom_bean.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none;border-right-width: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px;padding-top: 0px\" title=\"parsed_custom_bean\" border=\"0\" alt=\"parsed_custom_bean\" src=\"http:\/\/blog.jteam.nl\/wp-content\/uploads\/2011\/07\/parsed_custom_bean_thumb.png\" width=\"560\" height=\"367\" \/><\/a><\/p>\n<p>Not only are the annoying warnings gone, the IDE now also knows what type of bean is expected in an attribute, and uses this information in the autocomplete feature. Only beans of the expected type (or subtypes) are offered in the auto-complete.<\/p>\n<h2>Conclusion<\/h2>\n<p>When creating custom namespaces for Spring, the tool namespace allows you to tell IDE\u2019s (tested with IntelliJ, but I can&#8217;t imagine it won&#8217;t work for SpringSource Tool Suite) what type of beans elements produce and which types the custom attributes should reference.<\/p>\n<p>For an XSD with examples on how to use it, take a look at <a href=\"http:\/\/www.axonframework.org\/schema\/axon-core.xsd\" target=\"_blank\" rel=\"noopener\">axon-code.xsd<\/a>.<\/p>\n<p>The tool namespace provides a little more elements than just <code>exports<\/code> and <code>expected-type<\/code>, but I didn\u2019t quite figure out what they\u2019re used for. If you know, don\u2019t hesitate to write it in a comment.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spring offers many namespaces for the XML Application Context configuration to make your life a lot easier. Although not often needed, it is easy to create your own namespaces and provide custom elements. It makes configuration easier. However, I noticed that the some of the IDE support is lost. By chance, I found an undocumented [&hellip;]<\/p>\n","protected":false},"author":14,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","footnotes":""},"categories":[31,10],"tags":[153,70],"class_list":["post-3592","post","type-post","status-publish","format-standard","hentry","category-java","category-development","tag-namespace","tag-spring"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Enhancing IDE support for custom Spring Namespace elements - Trifork Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/trifork.nl\/blog\/enhancing-ide-support-for-custom-spring-namespace-elements\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Enhancing IDE support for custom Spring Namespace elements - Trifork Blog\" \/>\n<meta property=\"og:description\" content=\"Spring offers many namespaces for the XML Application Context configuration to make your life a lot easier. Although not often needed, it is easy to create your own namespaces and provide custom elements. It makes configuration easier. However, I noticed that the some of the IDE support is lost. By chance, I found an undocumented [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/trifork.nl\/blog\/enhancing-ide-support-for-custom-spring-namespace-elements\/\" \/>\n<meta property=\"og:site_name\" content=\"Trifork Blog\" \/>\n<meta property=\"article:published_time\" content=\"2011-07-07T11:31:10+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/blog.jteam.nl\/wp-content\/uploads\/2011\/07\/unparsed_custom_bean_thumb.png\" \/>\n<meta name=\"author\" content=\"Allard Buijze\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Allard Buijze\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/trifork.nl\/blog\/enhancing-ide-support-for-custom-spring-namespace-elements\/\",\"url\":\"https:\/\/trifork.nl\/blog\/enhancing-ide-support-for-custom-spring-namespace-elements\/\",\"name\":\"Enhancing IDE support for custom Spring Namespace elements - Trifork Blog\",\"isPartOf\":{\"@id\":\"https:\/\/trifork.nl\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/trifork.nl\/blog\/enhancing-ide-support-for-custom-spring-namespace-elements\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/trifork.nl\/blog\/enhancing-ide-support-for-custom-spring-namespace-elements\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/blog.jteam.nl\/wp-content\/uploads\/2011\/07\/unparsed_custom_bean_thumb.png\",\"datePublished\":\"2011-07-07T11:31:10+00:00\",\"author\":{\"@id\":\"https:\/\/trifork.nl\/blog\/#\/schema\/person\/a4e232a11dc57a2c4c581956ce6fde63\"},\"breadcrumb\":{\"@id\":\"https:\/\/trifork.nl\/blog\/enhancing-ide-support-for-custom-spring-namespace-elements\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/trifork.nl\/blog\/enhancing-ide-support-for-custom-spring-namespace-elements\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/trifork.nl\/blog\/enhancing-ide-support-for-custom-spring-namespace-elements\/#primaryimage\",\"url\":\"http:\/\/blog.jteam.nl\/wp-content\/uploads\/2011\/07\/unparsed_custom_bean_thumb.png\",\"contentUrl\":\"http:\/\/blog.jteam.nl\/wp-content\/uploads\/2011\/07\/unparsed_custom_bean_thumb.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/trifork.nl\/blog\/enhancing-ide-support-for-custom-spring-namespace-elements\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/trifork.nl\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Enhancing IDE support for custom Spring Namespace elements\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/trifork.nl\/blog\/#website\",\"url\":\"https:\/\/trifork.nl\/blog\/\",\"name\":\"Trifork Blog\",\"description\":\"Keep updated on the technical solutions Trifork is working on!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/trifork.nl\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/trifork.nl\/blog\/#\/schema\/person\/a4e232a11dc57a2c4c581956ce6fde63\",\"name\":\"Allard Buijze\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/trifork.nl\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/3e7130b2465615e105b1addd400a3f06?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/3e7130b2465615e105b1addd400a3f06?s=96&d=mm&r=g\",\"caption\":\"Allard Buijze\"},\"description\":\"Allard (@allardbz) is CTO of Trifork Amsterdam and founder of Axon Framework. He is a trainer and speaker at conferences on topics related to scalable architecture and domain driven design. He strongly believes that good craftsmanship can only be achieved through continuous and intensive exchange of experience with others. The last years, he has been investigating and applying CQRS to a number of projects. As a result, he created the Axon Framework, an open source Java framework that helps developers create scalable and extensible applications. Axon has a growing community and has already been successfully introduced in several high-profile projects around the world.\",\"url\":\"https:\/\/trifork.nl\/blog\/author\/allard\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Enhancing IDE support for custom Spring Namespace elements - Trifork Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/trifork.nl\/blog\/enhancing-ide-support-for-custom-spring-namespace-elements\/","og_locale":"en_US","og_type":"article","og_title":"Enhancing IDE support for custom Spring Namespace elements - Trifork Blog","og_description":"Spring offers many namespaces for the XML Application Context configuration to make your life a lot easier. Although not often needed, it is easy to create your own namespaces and provide custom elements. It makes configuration easier. However, I noticed that the some of the IDE support is lost. By chance, I found an undocumented [&hellip;]","og_url":"https:\/\/trifork.nl\/blog\/enhancing-ide-support-for-custom-spring-namespace-elements\/","og_site_name":"Trifork Blog","article_published_time":"2011-07-07T11:31:10+00:00","og_image":[{"url":"http:\/\/blog.jteam.nl\/wp-content\/uploads\/2011\/07\/unparsed_custom_bean_thumb.png","type":"","width":"","height":""}],"author":"Allard Buijze","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Allard Buijze","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/trifork.nl\/blog\/enhancing-ide-support-for-custom-spring-namespace-elements\/","url":"https:\/\/trifork.nl\/blog\/enhancing-ide-support-for-custom-spring-namespace-elements\/","name":"Enhancing IDE support for custom Spring Namespace elements - Trifork Blog","isPartOf":{"@id":"https:\/\/trifork.nl\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/trifork.nl\/blog\/enhancing-ide-support-for-custom-spring-namespace-elements\/#primaryimage"},"image":{"@id":"https:\/\/trifork.nl\/blog\/enhancing-ide-support-for-custom-spring-namespace-elements\/#primaryimage"},"thumbnailUrl":"http:\/\/blog.jteam.nl\/wp-content\/uploads\/2011\/07\/unparsed_custom_bean_thumb.png","datePublished":"2011-07-07T11:31:10+00:00","author":{"@id":"https:\/\/trifork.nl\/blog\/#\/schema\/person\/a4e232a11dc57a2c4c581956ce6fde63"},"breadcrumb":{"@id":"https:\/\/trifork.nl\/blog\/enhancing-ide-support-for-custom-spring-namespace-elements\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/trifork.nl\/blog\/enhancing-ide-support-for-custom-spring-namespace-elements\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/trifork.nl\/blog\/enhancing-ide-support-for-custom-spring-namespace-elements\/#primaryimage","url":"http:\/\/blog.jteam.nl\/wp-content\/uploads\/2011\/07\/unparsed_custom_bean_thumb.png","contentUrl":"http:\/\/blog.jteam.nl\/wp-content\/uploads\/2011\/07\/unparsed_custom_bean_thumb.png"},{"@type":"BreadcrumbList","@id":"https:\/\/trifork.nl\/blog\/enhancing-ide-support-for-custom-spring-namespace-elements\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/trifork.nl\/blog\/"},{"@type":"ListItem","position":2,"name":"Enhancing IDE support for custom Spring Namespace elements"}]},{"@type":"WebSite","@id":"https:\/\/trifork.nl\/blog\/#website","url":"https:\/\/trifork.nl\/blog\/","name":"Trifork Blog","description":"Keep updated on the technical solutions Trifork is working on!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/trifork.nl\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/trifork.nl\/blog\/#\/schema\/person\/a4e232a11dc57a2c4c581956ce6fde63","name":"Allard Buijze","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/trifork.nl\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/3e7130b2465615e105b1addd400a3f06?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3e7130b2465615e105b1addd400a3f06?s=96&d=mm&r=g","caption":"Allard Buijze"},"description":"Allard (@allardbz) is CTO of Trifork Amsterdam and founder of Axon Framework. He is a trainer and speaker at conferences on topics related to scalable architecture and domain driven design. He strongly believes that good craftsmanship can only be achieved through continuous and intensive exchange of experience with others. The last years, he has been investigating and applying CQRS to a number of projects. As a result, he created the Axon Framework, an open source Java framework that helps developers create scalable and extensible applications. Axon has a growing community and has already been successfully introduced in several high-profile projects around the world.","url":"https:\/\/trifork.nl\/blog\/author\/allard\/"}]}},"_links":{"self":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/posts\/3592","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/comments?post=3592"}],"version-history":[{"count":0,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/posts\/3592\/revisions"}],"wp:attachment":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/media?parent=3592"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/categories?post=3592"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/tags?post=3592"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}