Spring Batch Job Scope Unavailable - java

It seems like the Spring Batch 3.0.6 release points to the 2.2 schema by default.
In the spring.schemas file there is this definition
http\://www.springframework.org/schema/batch/spring-batch.xsd=/org/springframework/batch/core/configuration/xml/spring-batch-2.2.xsd
And when I add this namespace to my spring file, I then get the scope="step" option (in my IDE, although IntelliJ has been pretty reliable matching runtime issues)
...
xmlns:batch="http://www.springframework.org/schema/batch"
...
But everything seems to claim that scope="job" is invalid.
Is it the spring.schemas file doing this? Why would the 3.xx iteration point back to the 2.2 schemas?
I can't seem to get a declaration like xmlns:batch="http://www.springframework.org/schema/batch/spring-batch-3.0.xsd" to work. Surprisingly that totally invalidates the batch namespace. Even though the spring.schemas file points to 3.xx like so
http\://www.springframework.org/schema/batch/spring-batch-3.0.xsd=/org/springframework/batch/core/configuration/xml/spring-batch-3.0.xsd
If I do this:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
...
</beans>
I can then get the scope="step" to be valid, and everything seems to point to batch-3.0, but scope="job" is still invalid.
Does anyone have a clean example of importing batch & using a job scope declaration on a bean?
Thanks!

Related

How to load XSD files in spring when the app is working offline

I have gone through multiple stackoverflow threads but couldn't find a solution so posting this question. This is regarding how the xsd's are being mapped in spring container.
Below is the configuration in the context.xml
<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">
This works perfectly when the application is connected to internet, but the problem is when it works offline. It throws below error on start-up.
Caused by: org.xml.sax.SAXParseException; lineNumber: 7; columnNumber:
68; cvc-elt.1.a: Cannot find the declaration of element 'beans'.
If I explicitly point to the classpath like this,it works.
xsi:schemaLocation="http://www.springframework.org/schema/beans
classpath:/org/springframework/beans/factory/xml/spring-beans.xsd"
As per my understanding, Every spring jar shipped with the xsd and it is being mapped in META-INF/spring.schemas. The refered xds in the xml file should be able to load the local xsd available in the jar.
My concern is
Why it is unable to load the local xsd when there is no internet?
Of-course I can refactor all the xsi:schemaLocation to load from classpath but I have more than 25 xml files so instead of changing in all of them is there a better way to deal with it?
Spring version - spring-beans-5.1.5.RELEASE.jar
spring.schemas -
http\://www.springframework.org/schema/beans/spring-beans-2.0.xsd=org/springframework/beans/factory/xml/spring-beans.xsd
http\://www.springframework.org/schema/beans/spring-beans-2.5.xsd=org/springframework/beans/factory/xml/spring-beans.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.0.xsd=org/springframework/beans/factory/xml/spring-beans.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.1.xsd=org/springframework/beans/factory/xml/spring-beans.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.2.xsd=org/springframework/beans/factory/xml/spring-beans.xsd
http\://www.springframework.org/schema/beans/spring-beans-4.0.xsd=org/springframework/beans/factory/xml/spring-beans.xsd
http\://www.springframework.org/schema/beans/spring-beans-4.1.xsd=org/springframework/beans/factory/xml/spring-beans.xsd
http\://www.springframework.org/schema/beans/spring-beans-4.2.xsd=org/springframework/beans/factory/xml/spring-beans.xsd
http\://www.springframework.org/schema/beans/spring-beans-4.3.xsd=org/springframework/beans/factory/xml/spring-beans.xsd
http\://www.springframework.org/schema/beans/spring-beans.xsd=org/springframework/beans/factory/xml/spring-beans.xsd
http\://www.springframework.org/schema/tool/spring-tool-2.0.xsd=org/springframework/beans/factory/xml/spring-tool.xsd
http\://www.springframework.org/schema/tool/spring-tool-2.5.xsd=org/springframework/beans/factory/xml/spring-tool.xsd
http\://www.springframework.org/schema/tool/spring-tool-3.0.xsd=org/springframework/beans/factory/xml/spring-tool.xsd
http\://www.springframework.org/schema/tool/spring-tool-3.1.xsd=org/springframework/beans/factory/xml/spring-tool.xsd
http\://www.springframework.org/schema/tool/spring-tool-3.2.xsd=org/springframework/beans/factory/xml/spring-tool.xsd
http\://www.springframework.org/schema/tool/spring-tool-4.0.xsd=org/springframework/beans/factory/xml/spring-tool.xsd
http\://www.springframework.org/schema/tool/spring-tool-4.1.xsd=org/springframework/beans/factory/xml/spring-tool.xsd
http\://www.springframework.org/schema/tool/spring-tool-4.2.xsd=org/springframework/beans/factory/xml/spring-tool.xsd
http\://www.springframework.org/schema/tool/spring-tool-4.3.xsd=org/springframework/beans/factory/xml/spring-tool.xsd
http\://www.springframework.org/schema/tool/spring-tool.xsd=org/springframework/beans/factory/xml/spring-tool.xsd
http\://www.springframework.org/schema/util/spring-util-2.0.xsd=org/springframework/beans/factory/xml/spring-util.xsd
http\://www.springframework.org/schema/util/spring-util-2.5.xsd=org/springframework/beans/factory/xml/spring-util.xsd
http\://www.springframework.org/schema/util/spring-util-3.0.xsd=org/springframework/beans/factory/xml/spring-util.xsd
http\://www.springframework.org/schema/util/spring-util-3.1.xsd=org/springframework/beans/factory/xml/spring-util.xsd
http\://www.springframework.org/schema/util/spring-util-3.2.xsd=org/springframework/beans/factory/xml/spring-util.xsd
http\://www.springframework.org/schema/util/spring-util-4.0.xsd=org/springframework/beans/factory/xml/spring-util.xsd
http\://www.springframework.org/schema/util/spring-util-4.1.xsd=org/springframework/beans/factory/xml/spring-util.xsd
http\://www.springframework.org/schema/util/spring-util-4.2.xsd=org/springframework/beans/factory/xml/spring-util.xsd
http\://www.springframework.org/schema/util/spring-util-4.3.xsd=org/springframework/beans/factory/xml/spring-util.xsd
http\://www.springframework.org/schema/util/spring-util.xsd=org/springframework/beans/factory/xml/spring-util.xsd

Problem configuring Jolokia server and agent

I have a Spring Boot Java application that among other things uses Apache Camel to do a little route interception and data modification. We have a separate "camel routes" file (camelRoutes.xml) that defines the camel routes that will be used. There is also a bit of configuration in that file that, as best I understand, configures a Jolokia MBean server and Jolokia agent.
There is something about the Jolokia config XML that the system is not happy with. I've done some very quick Googling and it seems like it's specified properly (see section 9.3.2 in https://jolokia.org/reference/html/jmx.html). The problem manifest itself in various ways. When the file is open in the XML editor in eclipse, the corresponding XML is highlighted with an error (although it provides no information about what it thinks is wrong). More importantly, when I attempt to run the application, it fails with cascading exceptions, basically pointing to a problem in the config file.
Excerpts from camelRoutes.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jolokia="http://www.jolokia.org/jolokia-spring/schema/config"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.jolokia.org/jolokia-spring/schema/config http://www.jolokia.org/jolokia-spring/schema/config/jolokia-config.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
...
<context:mbean-export server="jolokiaServer" />
<jolokia:mbean-server id="jolokiaServer" />
<jolokia:agent lookupConfig="false"
systemPropertiesMode="never">
<jolokia:config autoStart="true" host="0.0.0.0"
port="${jolokia.port:8778}"
agentDescription="${jolokia.agentName:jolokia}" />
</jolokia:agent>
Errors are displayed in eclipse for the line where the jolokia:mbean-server and jolokia:agent are defined.
Small section of the exception trace when application is executed:
Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 85 in XML document from file [C:\Users\JO24447\workspace\RST_Service_Base\rust-service-base-rest\target\classes\rst_camel\camelRoutes.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 85; columnNumber: 45; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'jolokia:mbean-server'.
Any ideas what could be wrong?
In my case the cause was that I used the Maven assembly plugin which did not merge the spring.schemas files. I switched to the shader plugin and schema validation worked.

Wildfly looking in wrong directory

I recently startet working with JBoss' Wildfly 8.1 and the activiti framework.
I created two projects, one with my bpmn.xml file and the classes for the Service Tasks:
Process:
-src/main/
-impl.java
-src/resources/
-diagrams
-myprocess.bpmn.xml
-config
-activiti-context.xml
The other one holds the servlet
WebTest:
-src/main
-testServlet.java
-lib
-process.jar
in my servlet i implemented the init method to get the Activiti processEngine:
#Override
public void init() throws ServletException{
super.init();
engine = ProcessEngines.getDefaultProcessEngine();
}
I build the Webtest.war file and deploy it to
D:/path/to/workingdir/wildfly-8.1.0.Final/**standalone/deployments**/Webtest.war
Then i start up Widlfly using the provided standalone.bat, it starts up correctly and deploys to the context /Webtest, so far so good.
if i now access localhos:8080/Webtest/servlet i get the Exception:
org.activiti.engine.ActivitiException: couldn't initialize process engine from spring configuration resource vfs:/D:/path/to/workingdir/wildfly-8.1.0.Final/bin/content/TEST-1.war/WEB-INF/lib/process.jar/activiti-context.xml: null
the error with :null at the end implies that the file could not be accessed. of course it cannot, there is no bin/content!
my question now is: where does Widlfly get the idea to look at bin/content? it obviously was able to find the config file on itself, i never told spring or activiti to look in the process.jar, so the app finds the configuration in the classpath alright... then it proceeds to reading the file from an entirely different location that does not exist?
I dont know if this is of interesst, but here is my activiti-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<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-3.1.xsd">
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"/>
</beans>
thanks for any help or hints!

spring-beans.xsd does not define "local". Why?

Almost every spring project uses spring-beans.xsd (refers to it to be more precise). However, if you look at the file, http://www.springframework.org/schema/beans/spring-beans.xsd, you'll see that it is version 3.2 and doesn't have a definition for the attribute "local".
What's even more interesting, is that http://www.springframework.org/schema/beans/spring-beans-3.2.xsd does actually define "local".
Also since the file is pulled out of the jar (org/springframework/beans/factory/xml/spring-beans-3.2.xsd) due to spring.schema, I don't think any project will have compile or runtime issues.
Eclipse's xml validator on the other hand, I think, uses only the internet link and shows an xml error, more specifically :
"cvc-complex-type.3.2.2: Attribute 'local' is not allowed to appear in element 'ref'"
Is this is a bug?
Edit:
As per request, this is my spring header:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd">
Edit 2: here is where I'm using local
<bean id="bar"
class="org.springframework.batch.item.support.CompositeItemWriter">
<property name="delegates">
<list>
<ref local="foo" />
</list>
</property>
</bean>
<bean id="foo" class="java.lang.String" />
You should try to use <ref bean="someBean"/> instead.
As stated here: http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/
The local attribute on the ref element is no longer supported in the 4.0 beans xsd since it does not provide value over a regular bean reference anymore. Simply change your existing ref local references to ref bean when upgrading to the 4.0 schema.
As you might know Spring 3.x is not fully compatible with java 8, so you either use unsupported and outdated Java 7 with Spring 3.x, or upgrade both Spring and JDK. I would strongly recommend the latest
The http://www.springframework.org/schema/beans/spring-beans.xsd actually points to the 4.0 XSD, which does NOT have local. Additionally, There are bugs in eclipse with spring integration that could be the issue. INT-1353
Additionally, there /was/ a configuration option for eclipse to specify loading XSDs from Classpath, but I'm not 100% sure this works or even exists anymore. There is a screenshot of that here: https://stackoverflow.com/a/2896051/1958771
~ sheenobu -> curl -s http://www.springframework.org/schema/beans/spring-beans.xsd | md5
0483a5565138fe9f79c5fbe38c7c5969
~ sheenobu -> curl -s http://www.springframework.org/schema/beans/spring-beans-3.2.xsd | md5
1562baeab9550e2149e9608dbb3bbadd
~ sheenobu -> curl -s http://www.springframework.org/schema/beans/spring-beans-4.0.xsd | md5
0483a5565138fe9f79c5fbe38c7c5969
Spring (and Eclipse) will use whichever xsd you declared in the schemaLocation regardless of the one in the jar file. This is actually validation done by the XML parser that Spring uses underneath it all.
If you want to use the local attribute of ref, you will need to declare a schemaLocation that points to a schema that has the local attribute. Note that if you do do this, the generated context will need to be parseable by the BeanDefinitionParser that exists in your Spring jar.
I have solved the problem with using older http://www.springframework.org/schema/beans/spring-beans-3.2.xsd in xsi:schemaLocation. (As my project is "older" as well)

How to validate beans.xml using a local XSD?

In my application, I have some beans.xml files (for eeach module). each of these files contains required XSD declarations :
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:weld="http://jboss.org/schema/weld/beans"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd
http://jboss.org/schema/weld/beans http://jboss.org/schema/weld/beans_1_1.xsd">
Yesterday, due to some JBoss.org outage, schema files were unavailable, and as a consequence my beans.xml couldn't correctly validate.
It didn't prevent the project from validating, but slowed down project build (due to weld usage in tests, mainly).
So, what is a the solution, when using Weld 1.1.5 as CDI implementation, to not validate beans.xml during compilation, or to use a local XSD file (and if so, how to declare it, and where to put it in a maven project) ?
Just spoke with Pete Muir. He said its a bug. Would you mind creating a JIRA ticket please?

Categories