<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=gmazza" rel="nofollow">Glen Mazza</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-2177?redirect=false" rel="nofollow">SPR-2177</a></strong> and commented</p>
<p dir="auto">The 2.0 Spring form:errors tag will expand an error message, if a validation error is found in the command bean property, as follows:</p>
<p dir="auto">&lt;form:errors path="password"/&gt; becomes:<br>
&lt;span id="password.errors" name="password.errors"&gt;Password is missing&lt;/span&gt;</p>
<p dir="auto">An "id" and a "name" attribute is added to the span, both with the same value of "{commandbeanname}.errors".</p>
<p dir="auto">Two suggestions:</p>
<p dir="auto">1.)  One problem with having an "id" attribute automatically added to the span is that id's are supposed to be unique in an HTML document[1].  Although a rare use case, one could duplicate the form:errors tag for the same command bean property, with the result that the output HTML will have a duplicated ID.  Also, I'm unsure what additional benefits "id" buys the user that the already present "name" does not, so removing "id" might make sense.</p>
<p dir="auto">2.)  It might be beneficial to add a class attribute with the same value to all spans (regardless of property), perhaps called "formErrors".  This will allow one to conveniently use a CSS selector to specify that class value in order to apply common formatting (such as red fonts) to <strong>all</strong> error messages:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="*.formErrors {
	color: red
}"><pre class="notranslate"><code class="notranslate">*.formErrors {
	color: red
}
</code></pre></div>
<p dir="auto">Glen</p>
<p dir="auto">[1] <a href="http://www.w3.org/TR/REC-CSS2/selector.html#id-selectors" rel="nofollow">http://www.w3.org/TR/REC-CSS2/selector.html#id-selectors</a></p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.0 RC1</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=cam" rel="nofollow">Cameron Clarke</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-1216?redirect=false" rel="nofollow">SPR-1216</a></strong>* and commented</p>
<p dir="auto">Specific scenario, running JUnit test cases extending {<code class="notranslate">@link</code> org.springframework.test.AbstractTransactionalSpringContextTests} where the application utilises org.hibernate.jmx.StatisticsService as defined in spring-data-access-context.xml (see below), test fail due to :</p>
<p dir="auto">&lt;testcase classname="TestActionTypeDaoImpl" name="testGetAll" time="17.375"&gt;<br>
&lt;error message="Error creating bean with name 'jmxExporter' defined in class path resource [spring-data-access-context.xml]: Initialization of bean failed; nested exception is javax.management.InstanceAlreadyExistsException: Hibernate:name=hbmStats" type="org.springframework.beans.factory.BeanCreationException"&gt;org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmxExporter' defined in class path resource [spring-data-access-context.xml]: Initialization of bean failed; nested exception is javax.management.InstanceAlreadyExistsException: Hibernate:name=hbmStats<br>
javax.management.InstanceAlreadyExistsException: Hibernate:name=hbmStats<br>
at com.sun.jmx.mbeanserver.RepositorySupport.addMBean(RepositorySupport.java:452)<br>
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.internal_addObject(DefaultMBeanServerInterceptor.java:1410)<br>
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:936)<br>
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:337)<br>
at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:497)<br>
at org.springframework.jmx.export.MBeanExporter.registerMBean(MBeanExporter.java:413)<br>
at org.springframework.jmx.export.MBeanExporter.registerBeanInstance(MBeanExporter.java:389)<br>
at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:369)<br>
at org.springframework.jmx.export.MBeanExporter.registerBeans(MBeanExporter.java:296)<br>
at org.springframework.jmx.export.MBeanExporter.afterPropertiesSet(MBeanExporter.java:240)<br>
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1003)<br>
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:348)<br>
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)<br>
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)<br>
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:275)<br>
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:317)<br>
at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:80)<br>
at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:65)<br>
at org.springframework.test.AbstractSpringContextTests.loadContextLocations(AbstractSpringContextTests.java:121)<br>
at org.springframework.test.AbstractDependencyInjectionSpringContextTests.loadContextLocations(AbstractDependencyInjectionSpringContextTests.java:159)<br>
at org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:101)<br>
at org.springframework.test.AbstractDependencyInjectionSpringContextTests.setUp(AbstractDependencyInjectionSpringContextTests.java:127)<br>
&lt;/error&gt;</p>
<p dir="auto">spring-data-access-context.xml defined as ....</p>
<p dir="auto">...<br>
&lt;bean id="jmxExporter"<br>
class="org.springframework.jmx.export.MBeanExporter"<br>
depends-on="jmxServer"&gt;<br>
&lt;property name="beans"&gt;<br>
&lt;map&gt;<br>
&lt;entry key="Hibernate:name=hbmStats"&gt;<br>
&lt;ref bean="hibernateStatisticsJMXBean"/&gt;<br>
&lt;/entry&gt;<br>
&lt;/map&gt;<br>
&lt;/property&gt;<br>
&lt;/bean&gt;</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;bean id=&quot;hibernateStatisticsJMXBean&quot;      class=&quot;org.hibernate.jmx.StatisticsService&quot;&gt;
    &lt;property name=&quot;statisticsEnabled&quot;&gt;
        &lt;value&gt;true&lt;/value&gt;
    &lt;/property&gt;
    &lt;property name=&quot;sessionFactory&quot;&gt;
        &lt;ref bean=&quot;sessionFactory&quot;/&gt;
    &lt;/property&gt;
&lt;/bean&gt;

&lt;bean id=&quot;jmxServer&quot;         class=&quot;org.springframework.jmx.support.MBeanServerFactoryBean&quot;&gt;
    &lt;property name=&quot;defaultDomain&quot;&gt;
        &lt;value&gt;dummyDomain&lt;/value&gt;
    &lt;/property&gt;
&lt;/bean&gt;"><pre class="notranslate"><code class="notranslate">&lt;bean id="hibernateStatisticsJMXBean"      class="org.hibernate.jmx.StatisticsService"&gt;
    &lt;property name="statisticsEnabled"&gt;
        &lt;value&gt;true&lt;/value&gt;
    &lt;/property&gt;
    &lt;property name="sessionFactory"&gt;
        &lt;ref bean="sessionFactory"/&gt;
    &lt;/property&gt;
&lt;/bean&gt;

&lt;bean id="jmxServer"         class="org.springframework.jmx.support.MBeanServerFactoryBean"&gt;
    &lt;property name="defaultDomain"&gt;
        &lt;value&gt;dummyDomain&lt;/value&gt;
    &lt;/property&gt;
&lt;/bean&gt;
</code></pre></div>
<p dir="auto">...</p>
<p dir="auto">My current work around class....</p>
<p dir="auto">/** The SpringFrameworks (v.1.2.3) {<code class="notranslate">@link</code> org.springframework.jmx.export.MBeanExporter} does not detect</p>
<ul dir="auto">
<li>MBeans already registered and may attempt to register duplicate MBeans.  Either a unique / dynamic</li>
<li>object naming convention could be employed to avoid this or alternatively, simply ignore</li>
<li>{<code class="notranslate">@link</code> javax.management.InstanceAlreadyExistsException} exceptions which is the policy</li>
<li>employed by this class.</li>
<li>
</li><li>
<code class="notranslate">@author</code> Cameron Clarke</li>
<li>
<code class="notranslate">@version</code> <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="80849d621c70a0beebd8a845941f7719">$Id: $</math-renderer><br>
*/</li>
</ul>
<p dir="auto">import org.springframework.beans.factory.BeanFactoryAware;<br>
import org.springframework.beans.factory.DisposableBean;<br>
import org.springframework.beans.factory.InitializingBean;<br>
import org.springframework.jmx.export.MBeanExporter;</p>
<p dir="auto">import javax.management.JMException;<br>
import javax.management.InstanceAlreadyExistsException;</p>
<p dir="auto">public class SpringMBeanExporter extends MBeanExporter implements BeanFactoryAware, InitializingBean, DisposableBean<br>
{<br>
protected void registerBeans() throws JMException<br>
{<br>
try<br>
{<br>
super.registerBeans();<br>
} catch (InstanceAlreadyExistsException ex)<br>
{<br>
logger.error("Instance already exists, registering JMX bean failed.", ex);<br>
}<br>
}<br>
}</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 1.2.3</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398059319" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/5921" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/5921/hovercard" href="https://github.com/spring-projects/spring-framework/issues/5921">#5921</a> JMX InstanceAlreadyExistsException when deploying same app twice (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>