Error validating the file spring-ldap.xsd - java

i have this error in my bean configuration, but for another project works.. the xml is:
<?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:ldap="http://www.springframework.org/schema/ldap"
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/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd">
but in one project i have this error:
referenced file contains error http://www.springframework.org/schema/ldap/spring-ldap.xsd

UPDATE:
i modify my beam like this and work (i added conf. for pooling but is not important):
<!-- LDAP config -->
<bean id="contextSourceTarget" class="org.springframework.ldap.core.support.LdapContextSource">
<property name="url" value="${ldap.url}" />
<property name="base" value="${ldap.base}" />
<property name="userDn" value="${ldap.userDn}" />
<property name="password" value="${ldap.password}" />
<property name="pooled" value="false" />
</bean>
<bean id="contextSource"
class="org.springframework.ldap.pool.factory.PoolingContextSource">
<property name="contextSource" ref="contextSourceTarget" />
</bean>
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>

I guess it's because Pivotal's site is displaying captcha before showing the actual XSD,
see Spring schemaLocation fails when there is no internet connection
It depends on whether you get the error in the IDE or in the runtime.
If it's a specialized XML editor you should refer to the documentation of your editor on how to override/specify schema location, if it's in the runtime likely you have to check your project dependencies(pom.xml if it's a maven project).

Spring uses its own mechanism to get the XSD in classpath library (runtime).
Uses following files
META-INF/spring.handlers (to parse tag xml to object by an Handler)
example of spring-core-3.2.2.jar
http://www.springframework.org/schema/c=org.springframework.beans.factory.xml.SimpleConstructorNamespaceHandler
http://www.springframework.org/schema/p=org.springframework.beans.factory.xml.SimplePropertyNamespaceHandler
http://www.springframework.org/schema/util=org.springframework.beans.factory.xml.UtilNamespaceHandler
META-INF/spring.schemas (to identify the correct xsd used)
example of spring-core-3.2.2.jar
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd=org/springframework/beans/factory/xml/spring-beans-2.0.xsd
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd=org/springframework/beans/factory/xml/spring-beans-2.5.xsd
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd=org/springframework/beans/factory/xml/spring-beans-3.0.xsd
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd=org/springframework/beans/factory/xml/spring-beans-3.2.xsd
http://www.springframework.org/schema/beans/spring-beans.xsd=org/springframework/beans/factory/xml/spring-beans-3.2.xsd
http://www.springframework.org/schema/tool/spring-tool-2.0.xsd=org/springframework/beans/factory/xml/spring-tool-2.0.xsd
http://www.springframework.org/schema/tool/spring-tool-2.5.xsd=org/springframework/beans/factory/xml/spring-tool-2.5.xsd
http://www.springframework.org/schema/tool/spring-tool-3.0.xsd=org/springframework/beans/factory/xml/spring-tool-3.0.xsd
http://www.springframework.org/schema/tool/spring-tool-3.1.xsd=org/springframework/beans/factory/xml/spring-tool-3.1.xsd
http://www.springframework.org/schema/tool/spring-tool-3.2.xsd=org/springframework/beans/factory/xml/spring-tool-3.2.xsd
http://www.springframework.org/schema/tool/spring-tool.xsd=org/springframework/beans/factory/xml/spring-tool-3.2.xsd
http://www.springframework.org/schema/util/spring-util-2.0.xsd=org/springframework/beans/factory/xml/spring-util-2.0.xsd
http://www.springframework.org/schema/util/spring-util-2.5.xsd=org/springframework/beans/factory/xml/spring-util-2.5.xsd
http://www.springframework.org/schema/util/spring-util-3.0.xsd=org/springframework/beans/factory/xml/spring-util-3.0.xsd
http://www.springframework.org/schema/util/spring-util-3.1.xsd=org/springframework/beans/factory/xml/spring-util-3.1.xsd
http://www.springframework.org/schema/util/spring-util-3.2.xsd=org/springframework/beans/factory/xml/spring-util-3.2.xsd
http://www.springframework.org/schema/util/spring-util.xsd=org/springframework/beans/factory/xml/spring-util-3.2.xsd
The IDE want resolve the location of the XSD by schemaLocation, for this reason I suggest to remove XSD validation on your Eclipse.
Windows->Preferences->Validation-> "Suspend all validators"

Related

Spring SFTP connection - get file from SFTP server

I am new to spring. I am using spring to get files from remote server.
<?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:int="http://www.springframework.org/schema/integration"
xmlns:sftp="http://www.springframework.org/schema/integration/sftp"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/sftp
http://www.springframework.org/schema/integration/sftp/spring-integration-sftp-2.2.xsd">
<bean id="sftpSessionFactory"
class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
<property name="host" value="xxxxxxxx" />
<property name="user" value="wildfly" />
<property name="password" value="w!ldfly" />
<property name="port" value="22" />
</bean>
<int:channel id="sftpChannel" />
<sftp:inbound-channel-adapter id="triggerFtpInBound" auto-create-local-directory="true"
local-directory="/tmp/test" filename-pattern="*" channel="sftpChannel"
session-factory="sftpSessionFactory" remote-directory="/home/wildfly" delete-remote-files="true">
<int:poller cron="1/10 * * * * *" max-messages-per-poll="1" />
</sftp:inbound-channel-adapter>
I am using the following code.
ApplicationContext context = new ClassPathXmlApplicationContext("spring/config/spring-sftp.xml");
I am not getting any errors when i run it but i am not getting any files copied either. Please let me know the mistakes in my code. Thanks in advance.
It's difficult to debug just looking at static configuration.
The first step is to turn on DEBUG logging for org.springframework.integration and see what's happening.
If you can't figure it out from the logs, post them; if too big for here, use a github gist, pastebin, or similar.
Spring Integration uses jsch under the covers; you can enable its logging as described in the reference manual.
Adding "KnownHosts" property solved my issue. I am getting files transferred now.
<property name="knownHosts" value = "C:\knownhosts"/>

class path resource [target/jdbc.properties] cannot be opened because it does not exist

I am making a simple spring application. I already programed this on my other computer and decided to do it again from scratch to really commit it into memory. However my properties file for some reason is not in the class path. I right clicked the properties file and selected "copy qualified name" in eclipse to get the files path. However it is saying the file does not exsist and I find this very weird because I looked at my working example and it is in the same folder "target" and works fine.
When I click "copy qualified name" I get /DatabaseSpringframework/target/jdbc.properties I took away /DatabaseSpringframework/ and left the target/jdbc.properties and still the same error.
Here is my xml file...
<?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:tx="http://www.springframework.org/schema/tx"
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.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.1.xsd">
<context:component-scan base-package="com.learntoprogram"></context:component-
scan>
<context:property-placeholder location="target/jdbc.properties" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="username" value="${jdbc.username}"></property>
<property name="url" value="${jdbc.url}"></property>
<property name="driverClassName" value="${jdbc.driver}"></property>
</bean>
<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
</bean>
</beans>
Change location="target/jdbc.properties" to location="classpath:jdbc.properties".
That finds the property file in the classpath.

Spring referring bean present in other xml using local attribute of ref tag

I am creating sample spring program to understand, local attribute of ref tag.
I have created two bean files
first one [applicationcontext.xml]
<bean class="org.vik.spring.SequenceGenerator" name="sequenceProperty_Other">
<property name="prefix">
<ref local="prefixGeneratorOther" />
</property>
<property name="suffix" value="23"></property>
</bean>
Second xml file [prefix_context.xml]
<bean class="org.vik.spring.DatePrefixGenerator" id="prefixGeneratorOther" p:prefix="other"/>
I have created app context like below
ApplicationContext applicationContext = new FileSystemXmlApplicationContext("applicationcontext.xml" ,"prefix_context.xml");
When I request for bean "sequenceProperty_Other", spring successfully returns it
SequenceGenerator sequenceConstrutornerator = applicationContext.getBean( "sequenceProperty_Other",SequenceGenerator.class);
What I could understand from this, is that as "prefixGeneratorOther" bean in not in same xml file (applicationcontext.xml) and I am using local attribute to refer it, Spring should through exception. But in my case its working. Am I missing some thing.
applicationContext.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" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- <bean class="org.vik.spring.SequenceGenerator" name="sequence"> </bean> -->
<bean class="org.vik.spring.DatePrefixGenerator" id="prefixGenerator"
p:prefix="122333">
</bean>
<bean class="org.vik.spring.SequenceGenerator" name="sequenceProperty_Locale">
<property name="prefix">
<ref local="prefixGenerator" />
</property>
<property name="suffix" value="23"></property>
</bean>
<bean class="org.vik.spring.SequenceGenerator" name="sequenceProperty_Other">
<property name="prefix">
<ref local="prefixGeneratorOther" />
</property>
<property name="suffix" value="23"></property>
</bean>
prefix_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" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean class="org.vik.spring.DatePrefixGenerator" id="prefixGeneratorOther" p:prefix="other"/>
</beans>
Java class
ApplicationContext applicationContext = new FileSystemXmlApplicationContext("applicationcontext.xml",
"prefix_context.xml");
System.out.println(applicationContext.getBean("prefixGenerator", PrefixGenerator.class).getPrefix());
SequenceGenerator sequenceProperty = applicationContext.getBean("sequenceProperty_Locale",
SequenceGenerator.class);
System.out.println(sequenceProperty);
SequenceGenerator sequenceConstrutornerator = applicationContext.getBean("sequenceProperty_Other",
SequenceGenerator.class);
System.out.println(sequenceConstrutornerator);
This particular behavior works with any version after Spring 3.1.0 (included) in the 3.x branch. If you test this with the latest 3.0.x (which is 3.0.7) you'll get an exception. If you test with Spring 4, you'll get an exception, but a different one.
If you take a look carefully at the exception in Spring 3.0.7, this refers to XML parsing:
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:243)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:347)
at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
which means the restriction is at xml schema level (and I believe it's at Java code level, as well).
This behavior has changed in Spring 3.1.0 (and after) because of this JIRA issue. From all those JIRA issue it is linked to, this one seems to explain what happened: the restriction has been eliminated from 3.1 schema and the ref local entered in a kind of "deprecated" state (because in 3.1.x and 3.2.x one can use it) and in Spring 4 ref local has been entirely eliminated. In Spring 4 the documentation says ref local is not supported anymore and, also, the xsd schema has been updated (in the sense that ref doesn't accept local anymore).

Error occur when I start project that using DWR3.0 RC2 with Spring

I introduce DWR into my project these days. My project is using Spring 4, I was trying to integrate DWR with Spring by using annotation approch. Below are my code for integration work.
An error shown as below occured when I stratup my project on the Tomcat server.
the error:
java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.forName(Ljava/lang/String;)Ljava/lang/Class;
at org.directwebremoting.spring.DwrAnnotationPostProcessor.getBeanDefinitionClass(DwrAnnotationPostProcessor.java:96)
at org.directwebremoting.spring.DwrAnnotationPostProcessor.postProcessBeanFactory(DwrAnnotationPostProcessor.java:52)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPos
Processors(PostProcessorRegistrationDelegate.java:265)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:177)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:609)
web.xml
<servlet>
<servlet-name>dwr-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
dwr-dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
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-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.directwebremoting.org/schema/spring-dwr
http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd">
<context:annotation-config />
<context:component-scan base-package="com.xdfaint.webapp.apps.*.action" />
<dwr:configuration />
<dwr:annotation-config id="dwrAnnotationConfig" />
<dwr:url-mapping />
<dwr:controller id="dwrController" debug="true" />
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="order" value="1" />
</bean>
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
<property name="order" value="2" />
</bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/core/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
I haven't found any solution yet. Then I try to use Spring 3.2 instead, the startup successed with no error any more. I am not sure if there are problems when Spring 4 meets DWR3. Can any body help? Thx~
DWR haven't updated for a long time, and I am not using it anymore. But it is still great helpful that worth to read source codes for studying, like concept of how rest api binding, object operating. About object operating, I found some useful functions like setObject(), was using massively when I did a frontend components encapsulation work. Both setObject function codes and using demo list below, with it I can init a filed in a any nested level of the object, even if there are number of parents object of that new field hasn't been declared yet.
In Spring 4 there is no method forName in ClassUtils that only accepts String as an argument. As you can see from the JavaDoc here that method was already deprecated in Spring 3
It seems that DWR has not yet upgraded their code base to support Spring 4. Seems like you'll have to wait for that to happen (although the project seems to be non-active so I wouldn't count on that happening any time soon).

Passing jobParameters to bean in Spring Batch

I read a problem from the link https://stackoverflow.com/q/15784984/814074 and tried the solution given in above link.
However, I got the following error while running the code:
Error creating bean with name 'JobArgs' defined in class path resource [pipelineJob.xml]:
Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type '$Proxy2 implementing java.io.Serializable,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'com.test.genepanel.job.JobArguments' for property 'jobArguements'; nested exception is java.lang.IllegalStateException:
Cannot convert value of type [$Proxy2 implementing java.io.Serializable,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.test.genepanel.job.JobArguments] for property 'jobArguements': no matching editors or conversion strategy found
The xml contains
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.5.xsd">
<batch:job id="pipelineJob">
<batch:step id="initializationStep" next="CleanUPStep">
<batch:tasklet ref="initializationStepTasklet" />
</batch:step>
<batch:step id="CleanUPStep">
<batch:tasklet ref="cleanupTaskLet" />
</batch:step>
</batch:job>
<bean id="basicStep" class="com.test.mutation.steps.BasicStep" abstract="true">
<property name="testJobArgs" ref="JobArgs"/>
</bean>
<bean id="JobArgs" class="com.test.mutation.application.TestJobArguements">
<property name="jobArguements" ref="jobArg">
</property>
</bean>
<bean id="jobArg" class="com.test.genepanel.job.JobArguments" scope="step">
<constructor-arg value="#{jobParameters['jobOutputDir']}"/>
</bean>
<bean id="emptyTaskLet" class="com.test.mutation.steps.EmptyStep" scope="step" parent="basicStep" />
<bean id="cleanupTaskLet" class="com.test.mutation.steps.CleanUpStep" scope="step" parent="basicStep">
</bean>
<bean id="initializationStepTasklet" class="com.test.mutation.steps.InitializationStep" scope ="step" parent="basicStep">
</bean>
</beans>
Am I missing anything?
The easy way to use step scope is like this:
<bean id="myReader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
<property name="resource" value="file:#{jobParameters['input.file']}" />
<property name="linesToSkip" value="0" />
<property name="recordSeparatorPolicy" ref="simpleRecordPolicy" />
<property name="lineMapper" ref="journalSicIemtLineMapper" />
</bean>
Placing the step scope on the beans will delay his creation until the step it his referred is about to start. This is what Late-binding means, so you could access variables in the the ExecutionContext.
As the docs in the StepScope states:
beans with the StepScope will be aop:scoped-proxy. This means a proxy goes around the real object.
So when you define a regular Spring Beans (like you did with jobArg) and put the scope=step on it. You will have to find a way to retrieve the object inside this proxy when you want to set it in another bean (JobArgs)
I have looked all over the Spring references and I have not seen late binding in the constructor arguments so I am not sure it works. I assume you are setting the jobParameters in the JobArgs, in which case it should have the same scope="step"

Categories