<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=cltam96" rel="nofollow">chris tam</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-3250?redirect=false" rel="nofollow">SPR-3250</a></strong> and commented</p>
<p dir="auto">The problem is reported by Mark Menard in <a href="http://forum.springframework.org/showthread.php?t=35956" rel="nofollow">Spring support forum</a>. I have checked the source code and find out the problem come from LangNamespaceHandler "init" method. Currently the "init" method contains the following code:<br>
...<br>
public void init() {<br>
registerScriptBeanDefinitionParser("groovy", GroovyScriptFactory.class);<br>
registerScriptBeanDefinitionParser("jruby", JRubyScriptFactory.class);<br>
registerScriptBeanDefinitionParser("bsh", BshScriptFactory.class);<br>
}<br>
...<br>
The above code will throw ClassNotFoundException when either groovy, beanshell or jruby library is not found in the classpath. The DefaultNamespaceHandlerResolver will not register the "lang" namespace when "init" method throws the ClassNotFoundException.  The lang namespace requires that both groovy, beanshell and jruby library must be in the classpath. Is it possible to add some checking to the init method of LangNamespaceHandler to avoid the above dependency. For example:<br>
...<br>
public void init() {<br>
if (checkGroovyExists()) {<br>
registerScriptBeanDefinitionParser("groovy", GroovyScriptFactory.class);<br>
}<br>
if (checkJRubyExists()) {<br>
registerScriptBeanDefinitionParser("jruby", JRubyScriptFactory.class);<br>
}<br>
if (checkBshExists()) {<br>
registerScriptBeanDefinitionParser("bsh", BshScriptFactory.class);<br>
}</p>
<p dir="auto">// what to do if all the above jars are not found???</p>
<p dir="auto">}</p>
<p dir="auto">private boolean checkGroovyExists() {<br>
try {<br>
Class.forName("groovy.lang.GroovyObject") ;<br>
return true ;<br>
} catch(Exception e) {<br>
return false ;<br>
}<br>
}</p>
<p dir="auto">private boolean checkBshExists() {<br>
try {<br>
Class.forName("bsh.Interpreter") ;<br>
return true ;<br>
} catch(Exception e) {<br>
return false ;<br>
}<br>
}</p>
<p dir="auto">private boolean checkJRubyExists() {<br>
try {<br>
Class.forName("org.jruby.runtime.builtin.IRubyObject") ;<br>
return true ;<br>
} catch(Exception e) {<br>
return false ;<br>
}<br>
}<br>
...<br>
Thanks for all the help from spring team.</p>
<p dir="auto">cheers<br>
chris tam<br>
xenium</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.0.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="398076226" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/7942" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/7942/hovercard" href="https://github.com/spring-projects/spring-framework/issues/7942">#7942</a> Cannot find "lang" namespace handler unless all library jars are present (<em><strong>"is duplicated by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398076341" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/7958" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/7958/hovercard" href="https://github.com/spring-projects/spring-framework/issues/7958">#7958</a> NoClassDefFoundError when groovy isn't on classpath (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=ojs" rel="nofollow">Oliver Siegmar</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-9067?redirect=false" rel="nofollow">SPR-9067</a></strong> and commented</p>
<p dir="auto">Consider this configuration:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;mvc:resources mapping=&quot;/static/**&quot; location=&quot;/WEB-INF/resources/immutable/&quot;/&gt;"><pre class="notranslate"><code class="notranslate">&lt;mvc:resources mapping="/static/**" location="/WEB-INF/resources/immutable/"/&gt;
</code></pre></div>
<p dir="auto">The resource directory /WEB-INF/resources/immutable/ contains several files and subdirectories. One subdirectory is called images.</p>
<p dir="auto">A browser request to /static/nonexistingfile.png results in a 404 HTTP error. But a request to /static/images (existing directory, without a file name specified) results in a FileNotFoundException:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/resources/immutable/images]
        at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:118) ~[spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
        at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.writeContent(ResourceHttpRequestHandler.java:240) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
        at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.handleRequest(ResourceHttpRequestHandler.java:141) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
        at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:49) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:621) ~[servlet-api.jar:na]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) ~[servlet-api.jar:na]"><pre class="notranslate"><code class="notranslate">java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/resources/immutable/images]
        at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:118) ~[spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
        at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.writeContent(ResourceHttpRequestHandler.java:240) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
        at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.handleRequest(ResourceHttpRequestHandler.java:141) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
        at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:49) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:621) ~[servlet-api.jar:na]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) ~[servlet-api.jar:na]
</code></pre></div>
<p dir="auto">I think the getResource(HttpServletRequest) method in ResourceHttpRequestHandler should also check if the requested resources is a File.</p>
<p dir="auto">On a high volume website this can cause tons of FileNotFoundExceptions due to robot visits. This is why I classified this issue with major priority.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.1 GA</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="398116957" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13712" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13712/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13712">#13712</a> Spring MVC resources handler generates a 500 internal error when accessing a directory resource (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>
<p dir="auto"><strong>Referenced from:</strong> commits <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/f8238f52433432d78a6f6d0a9352f5b1efa1cb02/hovercard" href="https://github.com/spring-projects/spring-framework/commit/f8238f52433432d78a6f6d0a9352f5b1efa1cb02"><tt>f8238f5</tt></a></p>