3

I've been struggling with this issue for several days now. I am trying to initialize a standard Spring project with the usual spring namespaces: beans, aop, context, util... my current, very initial, beans.xml file is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:aop="http://www.springframework.org/schema/aop"
  xmlns:util="http://www.springframework.org/schema/util"
  xsi:schemaLocation="
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xml
     http://www.springframework.org/schema/context http://www.springframework.org/schema/beans/spring-context.xml
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/beans/spring-aop.xml
     http://www.springframework.org/schema/util http://www.springframework.org/schema/beans/spring-util.xml"
</beans>

When I attempt to compile and run the project in Glassfish, I hit an IllegalStateException while invoking org.glassfish.weld.WeldDeployer. Further down it states that the XML of dependent documents must be well formed and shows the first line of one of the dependent files (e.g. spring-beans.xml) which is clearly HTML. After some further digging, I found that indeed in my mavencachedirs where these .xsd files are cached, every single one had identical HTML content referencing a 404 Not Found. I am working offline with internal maven repositories, but this should not be a problem given that my dependent Spring jar files all have the appropriate spring.schemas and spring.handlers files. It simply seems like my project is failing to recognize them.

I'm a bit new to Spring, but I feel like I've done my due diligence in researching this issue. Any suggestions that may point me in the right direction would be greatly appreciated.


UPDATE - Following some of the tips posted in Spring schemaLocation fails when there is no internet connection, I consolidated my spring.handlers and spring.schemas files into two files in src/main/resources/META-INF. Running getResource returns the consolidated version of each file in this directory. That said, this still did not resolve the problem.


UPDATE 2 - I've reproduced this issue at home. I created a new Spring project on Netbeans 7.3.1 using the following archetype:

Group ID: co.ntier
Version: 1.0.2
Artifact ID: spring-mvc-archetype
Repository: http://repo.maven.apache.org/maven2/

Once the project was created, I added a beans.xml file to the classpath and stripped it down to it's most basic form:

<?xml version="1.0" encoding="windows-1252"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"
/>

I built the project and deployed to Glassfish 4.0 through NetBeans while still connected to the internet. This worked as expected with no errors. However, when I disconnected the computer from the internet and deployed again (AND cleared the cached xsd files from ...Netbeans\Cache\7.3.1\mavencachedirs), I got the following error several times:

WARNING: WELD-001210 Warning when validating file:/C:/Users/Elliott/Desktop/Development/SpringTest/target/SpringTest/WEB-INF/beans.xml@5 against xsd. schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/beans/spring-beans.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not .

I understand that Spring is supposed to be reading from the spring.schemas and spring.handlers files to locate these resources, but it clearly isn't! I challenge anybody to attempt to reproduce this issue and demonstrate that this is actually working as it should be. Right now I'm not convinced.

Community
  • 1
  • 1
  • have a look at http://stackoverflow.com/questions/1729307/spring-schemalocation-fails-when-there-is-no-internet-connection – Frederic Close Dec 06 '13 at 16:34
  • @FredericClose Thanks for the comment. Tried these before. First, I am not using schema urls with the version, even though the versioned entries _are_ found in the respective jars. A test program that calls getClass().getResource("/META-INF/spring.schemas") yields one of the spring.schemas files on the classpath, so it seems like Spring should be able to find all of them. However, it's clear that when the project is run that they are not found properly. Can't tell if this is a Spring issue, a Netbeans issue, or a WAR+Glassfish issue. Any other suggestions on how I could debug the problem? – VillagElliott Dec 06 '13 at 16:57
  • Your header is wrong, they all end in `.xml` whereas you should refer to `.xsd` files. – M. Deinum Dec 06 '13 at 17:37
  • Thanks M. Deinum. You're right. But that was just a typo when I transcribed the file. The problem still occurs when they are properly named... – VillagElliott Dec 09 '13 at 13:18

1 Answers1

0

PROGRESS!!

OK. I'm 90% sure I've figured out the problem. When I created the beans.xml file, Netbeans creates a nb-configuration.xml file with the following in it:

<spring-data xmlns="http://www.netbeans.org/ns/spring-data/1">
    <config-files>
        <config-file>beans.xml</config-file>
    </config-files>
    <config-file-groups/>
</spring-data>

If I create a servlet in the web.xml file:

<servlet>
    <servlet-name>SpringDispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

and rename beans.xml file to SpringDispatcher-servlet.xml, the project compiles and loads the xsd files correctly, whether online or offline.

Since this worked when using the SpringDispatcher-servlet.xml, but not with beans.xml configured by Netbeans, I think it's safe to assume that when Netbeans is configured to load a spring config file through nb-configuration, it fails to reference the required spring.schemas and spring.handlers files in the classpath.

Maybe I'm completely wrong and just super noob-y when it comes to Spring (I am), but it doesn't seem like this behavior is correct. Regardless, at least I have a way to move forward now.