getting error in Spring Batch, Job builder and step builder. get function not working with it - spring-batch

#Bean
public Step step1() {
return this.stepBuilder.get("step1")
I'm getting this error:
The method get(String) is undefined for the type StepBuilder please
assist
Solution for the mentioned, i'm getting error in spring batch.

Related

UnknownServiceException: Unknown service requested [EnversService]

I want to run Hibernate in OSGi. I have added the standard Hibernate OSGi bundle and a Blueprint implementation, so that Envers gets registered right on startup.
Even without any kind of documentation I found out you have to start Envers, because... I doubt there is a logical reason, it does not work otherwise.
However now, even though Envers was registered in Blueprint, I get the following exception:
org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.envers.boot.internal.EnversService]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:184)
at org.hibernate.envers.boot.internal.TypeContributorImpl.contribute(TypeContributorImpl.java:22)
at org.hibernate.boot.internal.MetadataBuilderImpl.applyTypes(MetadataBuilderImpl.java:280)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.populate(EntityManagerFactoryBuilderImpl.java:798)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:187)
at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:34)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:165)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:114)
at org.hibernate.osgi.OsgiPersistenceProvider.createEntityManagerFactory(OsgiPersistenceProvider.java:78)
at org.acme.project.Main.startSession(PersistenceUnitJpaProvider.java:38)
The stack trace starts at PersistenceProvider#createEntityManagerFactory in the following snippet:
public class Main {
private EntityManagerFactory entityManagerFactory;
public void startSession(Map<String, Object> config) {
BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
ServiceReference<PersistenceProvider> serviceReference = context.getServiceReference(PersistenceProvider.class);
PersistenceProvider persistenceProvider = context.getService(serviceReference);
this.entityManagerFactory = persistenceProvider.createEntityManagerFactory("persistenceUnit", config);
context.ungetService(serviceReference);
}
I found this bug, and maybe this issue is fixed in the current version of Hibernate. But since the bundle IDs are broken, I have to use 5.1.
So Envers is registered, but not really. What could be the reason for such a strange error message?

Spring Batch - How to keep job running when exception occur?

I try to write example app using spring batch:
#Bean
public Step testStep() {
return steps.get("testStep").<String,String>chunk(1)
.reader(testReader())
.processor(testProcessor())
.writer(testWriter())
.listener(testListener())
.build();
}
When I throw exception in reader or processor or writer, the job stopped with status FAILED. How can I make job ignore exception and keep running.
I'm not use any xml config, just annotation and class. Please give me a hint or link.
Thanks for any support!
Edit: Can we add skip dynamically, like I post in answer below.

Spring STS - unable to resolve properties

This question is not related with spring, but with STS tool suite or with spring eclipse IDE. Given following declaration of the class
#Configuration()
#Import({ WebSharedConfig.class, SpringSecurityConfig.class })
#ComponentScan({ "com.finovera.web", "com.finovera.platformServices","com.finovera.authentication" })
#PropertySources(value = { #PropertySource({ "${FINOVERA_PROPERTIES}" }),
#PropertySource(value = { "${STATIC_OVERRIDE_PROPERTIES}", }, ignoreResourceNotFound = true) })
#Scope("singleton")
#EnableTransactionManagement
public class CabinetConfig extends WebMvcConfigurationSupport {
}
I am seeing following exception in STS plugin (org.springframework.ide.eclipse.beans.core)
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.finovera.web.config.CabinetConfig]; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'FINOVERA_PROPERTIES' in string value "${FINOVERA_PROPERTIES}"
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:181)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:321)
Error is simple as properties name is passed to JVM when application starts. The application run time code works fine, but STS does not. Lot of functionality missing as main configuration scan fails. Commenting out property sources annotation, everything works fine.
How do I pass property value to STS or convince it to ignore PropertySources annotation?
I think this is a limitation in the current implementation. Please file an enhancement request against: https://issuetracker.springsource.com/browse/STS and we can try to fix this for the next release of STS and Spring IDE.

RMI using spring. Executing method in server with object as parameter

I am trying to execute a method from client to server using RMI.
As long as the parameters are String, it is getting executed correctly. If I am using object as method parameter.
I am getting following exception :
java.rmi.UnmarshalException: Error unmarshaling return; nested exception is:
java.lang.ClassNotFoundException: org.eclipse.persistence.exceptions.DatabaseException (no security manager: RMI class loader disabled)
Server configuration:
#Bean
public RmiServiceExporter getUserService() {
RmiServiceExporter exporter = new RmiServiceExporter();
exporter.setService(userService);
exporter.setServiceName("UserService");
exporter.setServiceInterface(UserService.class);
exporter.setRegistryPort(1192);
exporter.setReplaceExistingBinding(true);
return exporter;
}
Client configuration:
public #Bean RmiProxyFactoryBean getUserService() {
RmiProxyFactoryBean rmi = new RmiProxyFactoryBean();
rmi.setServiceInterface(UserService.class);
rmi.setServiceUrl("rmi://localhost:1192/UserService");
return rmi;
}
Test code :
User user = userService.getUser(String userName);
Works perfectly fine.
userService.save(user);
Save user throws RMI exception.
I made sure that the package name for User object in server and client is same. Still I am getting the exception.
Am I missing any configuration? How can I make RMI server to load the other classes?

Spring Batch - Call as webservice

I have a Spring Batch job. I am new to Spring Batch and have always been called via the CommandLineJobRunner.
This is what my call looks like:
org.springframework.batch.core.launch.support.CommandLineJobRunner spring-batch-myProject.xml SpringJobBean.MyProjectImportDataJob
Now I have to call my batch job from within a webservice (Spring MVC). In my endpoint this is the invoke call. I need to call the batch job in the if statement. How would I do this? I read about JobLauncher...but not sure how to tell it what to launch?
protected Object invokeInternal(Object aObj) throws Exception {
RunDataProcessingImportRequest request = (RunDataProcessingImportRequest) aObj;
RunDataProcessingImportResponse response = new RunDataProcessingImportResponse();
if (request.getDataProcessingType().equals(PROJECT_TYPE)){
response.setResultCd(1);
} else {
response.setResultCd(0);
response.setErrorCode(1l);
response.setErrorMessage("Incorrect process type");
}
return response;
}
The answer to this really depends on the version of Spring Batch you're using.
If you're using 2.0.x or older you can use Spring Batch Admin to provide REST endpoints for starting/stopping/etc jobs. All you need to do is add the jars to your app and provide a small amount of configuration.
If you're using 2.2.x or newer and are allowed to use the snapshot versions of Spring Batch Admin, the same applies as mentioned above.
If you're not interested in using Spring Batch Admin, you'll need to write your own endpoint and launch the job from there. However, it should be fairly trivial (I haven't tested the code below):
#Controller
public class JobLaunchingController {
#Autowire
JobLauncher jobLauncher;
#Autowire
JobRegistry jobRegistry;
#RequestMapping("/launch")
public #ResponseBody JobExecution launch(
#RequestParam(value="name", required=true) String name,
#RequestParam(value="params", required=false) String params) {
Job job = jobRegistry.getJob(name);
JobParametersBuilder paramsBuilder = new JobParametersBuilder();
if(params != null) {
// parse job parameters
}
return jobLauncher.run(job, paramsBuilder.toJobParameters());
}
}
The above code assumes you have more than one job to provide the ability to execute. If not, you could just #Autowire the Job itself into your controller if you wanted (instead of the JobRegistry).
You can read more about REST services in Spring here: https://spring.io/guides/gs/rest-service/
You can read more about the JobLauncher here: http://docs.spring.io/spring-batch/trunk/apidocs/org/springframework/batch/core/launch/JobLauncher.html
Finally, you can read more about the JobRegistry in section 4.6.2 here: http://docs.spring.io/spring-batch/reference/html/configureJob.html