Spring MVC schemas and corresponding jar files - java

I am new to Spring and looking for some help trying to figure what Spring schemas correspond to what jar files in my project class path. I need to know that since I am looking to upgrade to the later version of Spring. The following is the schemas I have in my xml files
in my applicationContext-dataaccess.xml
b:beans xmlns="http://www.springframework.org/schema/security"
xmlns:b="http://www.springframework.org/schema/beans"
xmlns:jee="http://www.springframework.org/schema/jee"
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-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd">
in my applicationContext-resourcebundle.xml
<b:beans xmlns="http://www.springframework.org/schema/security"
xmlns:b="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-3.0.xsd">
in my applicationContext-security.xml
<b:beans xmlns="http://www.springframework.org/schema/security"
xmlns:b="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-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
in my app-servlet.xml
<b:beans xmlns="http://www.springframework.org/schema/security"
xmlns:b="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
The following is the Spring jar files I see in the class path of my project
\WEB-INF\lib\spring-xml-2.0.2.RELEASE.jar"
\WEB-INF\lib\org.springframework.aop-3.1.2.RELEASE.jar"
\WEB-INF\lib\org.springframework.asm-3.1.2.RELEASE.jar"
\WEB-INF\lib\org.springframework.beans-3.1.2.RELEASE.jar"
\WEB-INF\lib\org.springframework.context.support-3.1.2.RELEASE.jar"
\WEB-INF\lib\org.springframework.context-3.1.2.RELEASE.jar"
\WEB-INF\lib\org.springframework.core-3.1.2.RELEASE.jar"
\WEB-INF\lib\org.springframework.expression-3.1.2.RELEASE.jar"
\WEB-INF\lib\org.springframework.jdbc-3.1.2.RELEASE.jar"
\WEB-INF\lib\org.springframework.transaction-3.1.2.RELEASE.jar"
\WEB-INF\lib\org.springframework.web.servlet-3.1.2.RELEASE.jar"
\WEB-INF\lib\org.springframework.web-3.1.2.RELEASE.jar"
\WEB-INF\lib\spring-security-acl-3.0.5.RELEASE.jar"
\WEB-INF\lib\spring-security-config-3.0.5.RELEASE.jar"
\WEB-INF\lib\spring-security-core-3.0.5.RELEASE.jar"
\WEB-INF\lib\spring-security-taglibs-3.0.5.RELEASE.jar"
\WEB-INF\lib\spring-security-web-3.0.5.RELEASE.jar"
\WEB-INF\lib\spring-ws-core-2.0.2.RELEASE.jar"
\WEB-INF\lib\spring-ws-security-2.0.2.RELEASE.jar"
\WEB-INF\lib\spring-ws-support-2.0.2.RELEASE.jar"
What would be the best approach to upgrade to a later version of Spring ?Take the version names out of the schemas and just copy jar files into the class path of my project? What Spring jar files do I need for my project?
Thank you in advance for any information about this!

Take the version names out of the schemas and just copy jar files into the class path of my project?
Yes. By removing the versions from the files, the schemas will be searched and found in the jar files, since spring is stripping the schema version when building the jars. This way if your dependencies are correct, your configuration XML will be validated against the proper schemas
With the build tool. For what concerns your first and the third question. Using a proper build-managment tool, and using it properly is your best choice, the following answer can illustrate a maven based approach that gives you most flexibility when upgrading.
Without the build tool. On the other hand if you can't use any build tool, there's a dedicated github page explaining how to proceed
Although it is strongly recommended that Spring Framework users take
advantage of the transitive dependency management features of build
systems like Gradle, Maven, and Ivy, some teams cannot use these
tools. This is usually due to corporate restrictions or working with
legacy builds. If you're in this boat, you may want to build a Spring
Framework distribution zip that contains all optional and required
runtime dependencies.

Related

How can I make spring.xml's xsi:schemaLocation work when my app is offline (finished product is an offline artifact)

I have an application which will only work offline but because of how the project is setup it requires an internet connection start-up. I know the issue is the xsi:schemaLocation attribute in the spring.xml, but don't know Spring well enough to know how to set a project up pointing to the schemas locally.
<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:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.5.xsd">
does anybody have any experience here?
If you ommit the version numbers from the schema's, they will be loaded from the jar files, so
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
Before Spring jar's are released, the version is stripped off and the schemas are packaged with the jars. Its even a good practice to use the schema's without the version as it may point to classpath/version mismatch early

Enable CrudRepository in Spring java config

I'm trying to implement Spring's repositories in my DAL. I'm following this guide.
At the third step of "1.2 Query methods" paragraph we need to activate the repository package scanning with the following XML configuration
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
<repositories base-package="com.acme.repositories" />
</beans>
In my project I'm using only java config so this declaration is a little problematic for me. What is the right way to make things done in java conf in this case?
Thank you
You need to add the following annotation to your configuration class:
#EnableJpaRepositories("com.acme.repositories")

IntelliJ IDEA validates toward wrong XSD

I have defined the following transaction manager:
<tx:annotation-driven transaction-manager="txManager" mode="aspectj" />
and have the following root element:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
Everything works fine, but IntelliJ gives me a error marker on
mode="aspectj"
saying it is not allowed. I have followed where it gets the xsd from, and it links to the tx 2.0 xsd - which explains the error message, as I need 2.5 to use the mode annotation.
Is it possible to somehow give IntelliJ a hint that i should validate toward 2.5 rather than 2.0?
If you open up the jar file that the schemaLocation should point to the xsd according to this screen shot:
Then you'll see that IntelliJ has a bunch of xsd files for different versions of Spring:
This means that you really have all the schemas you need.
If your bean definitions file has problems then your schemaLocation must point to the wrong version in the Spring jar file:
Check the Settings | Schemas and DTDs and verify that you haven't accidentally manually set it to point to the wrong xsd file:
If it is wrong then you'll have to remove that line using the minus sign. This will cause IntelliJ to go back to it's default values:
After that you should be seeing the same thing as in the first screen shot.
I was having a similar problem trying to use spring security and beans in the same xml config. IntelliJ was insisting on validating using the security xsd version 2.0 despite everything telling it to use version 3.1.
I was able get IntelliJ to figure it out by changing the default namespace between security and beans.
I originally had:
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
So I switched it to:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
After that IntelliJ was validating using the correct xsd. I'm not sure if this was a bug with IntelliJ or something I was doing wrong, but it works now.
Hopefully this helps someone in the future.

JAX-WS Schema http://jax-ws.dev.java.net/spring/servlet.xsd not able to be found

I am implementing JAX-WS with Spring framework.
The following is my Spring applicationContext.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ws="http://jax-ws.dev.java.net/spring/core"
xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://jax-ws.dev.java.net/spring/core
http://jax-ws.dev.java.net/spring/core.xsd
http://jax-ws.dev.java.net/spring/servlet
http://jax-ws.dev.java.net/spring/servlet.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
">
However, Eclipse is complaining:
Referenced file contains errors (http://jax-ws.dev.java.net/spring/servlet.xsd).
After investigation, I find the URL:
http://jax-ws.dev.java.net/spring/servlet.xsd
Does not exist.
Instead, it seems be move to:
http://jax-ws.java.net/spring/servlet.xsd
(You can open this link in the brower)
Therefore, I updated XSD schema URL from
http://jax-ws.dev.java.net/spring/servlet.xsd
to
http://jax-ws.java.net/spring/servlet.xsd
Now my applicationContext.xml looks like this:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ws="http://jax-ws.dev.java.net/spring/core"
xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://jax-ws.dev.java.net/spring/core
http://jax-ws.java.net/spring/core.xsd
http://jax-ws.dev.java.net/spring/servlet
http://jax-ws.java.net/spring/servlet.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
">
Actually with this change the Eclipse error goes away.
The problem is after launching the web service in Tomcat 7, I get the following runtime error instead:
org.xml.sax.SAXParseException; lineNumber: 20; columnNumber: 29; schema_reference.4: Failed to read schema document 'http://jax-ws.java.net/spring/servlet.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not .
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.warning(ErrorHandlerWrapper.java:99)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:433)
Please advise.
Thank you very much.
Regards,
Your problem is that you change the location from http://jax-ws.dev.java.net/spring/servlet.xsd to http://jax-ws.java.net/spring/servlet.xsd. Even though the latter one is the right url, it does not match what is defined in your jaxws-spring.jar META-INF/spring.schema file. That file should have the following content
http\://jax-ws.dev.java.net/spring/core.xsd=spring-jax-ws-core.xsd
http\://jax-ws.dev.java.net/spring/servlet.xsd=spring-jax-ws-servlet.xsd
http\://jax-ws.dev.java.net/spring/local-transport.xsd=spring-jax-ws-local-transport.xsd
Spring uses this mapping to search the schema in the classpath rather than to internet. Those schema files are located at the root of the jaxws-spring.jar file.
Please take a look Registering the handler and the schema
are you using spring in your project?, I had the same problem, but when I included spring-jaxws in my maven dependencies the problem solved, in fact, yo can see in that jar that the META-INF/spring.schemas file is redefining the XSDs locations
Resources have moved, final config should be:
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://jax-ws.dev.java.net/spring/core
http://jax-ws.java.net/spring/core.xsd
http://jax-ws.dev.java.net/spring/servlet
http://jax-ws.java.net/spring/servlet.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"
default-lazy-init="true">
Probably not a case with yours. But in such a scenario, do clean and make a fresh build. Reason being the older spring jar and xsd from there would be taken if the two jars exits. Hope that helps for other guys .... generically this exception will be thrown for many reasons.

Is there a common place out there contains declarations for all Spring XMLs

I need to write a applicationContext.xml for my Spring Framework 3 application, but I cann't find out its XML Declaration. Anyone could show me place to get it?
Likewise, is there a common place defining declarations for all Spring XMLs? (Or other XMLs being around.)
Below is a declaration example for Spring 2.5 I found out by googling:
<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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
</beans>
This is all described in the Spring documentation see 3.2.1 Configuration metadata for the basic structure and Appendix C. XML Schema-based configuration for details of the other declarations you could use.

Categories

Resources