Does spring retry dependency covered under spring batch in spring initializr? - spring-batch

Trying to add Retry dependency in spring initializr, but only batch is showed?
Does it mean need to add spring-batch and use retry?

No. Not every possible modules that the Spring ecosystem has is on start.spring.io. We try to reduce things to what's relevant for a getting started experience.
With a project generated on start.spring.io, you already get dependency management for Spring Retry so, if you prefer to use it directly without Spring Batch or another module that uses it, you can add the jar directly. You don't need to specify a version as this is taken care for you.

Related

Does Spring LDAP (Spring Data Repository) support repository customization?

I am using Spring LDAP 2.3.1 and want to customize my repository by adding my own create method. I was hoping I could use the functionality described in section 2.6 of the Spring Data Commons documentation but it did not seem to work.
Is this functionality implemented for Spring LDAP?
Not sure what you mean with own create method. Custom repository implementations are available for every Spring Data module, see reference docs.

Packaging JPA entities in a jar inside a Spring Boot application

I am refactoring a JEE REST (using JAX-RS 2.0) application as a Spring Boot application. My old app is packaged in a .war and has a jar file with entities and the persistence.xml configuration file for JPA. This jar is copied into WEB-INF/lib directory. I know Spring JPA works a different way and I don't use persistence.xml now but I wonder if I can package my JPA entity classes in a jar and include them in my Spring Boot apps just like I am doing now. This way I can easily reuse that jar in different Spring Boot Applications.
I'm pretty certain you can do this since I have done the same on one of my projects very recently. The only thing you need to do is make sure that you add an #EntityScan annotation on your main Spring Boot config class with the base package of your entities in the JAR.
#EntityScan("my.external.jar.entity.package")
Spring Boot doesn't really care whether the JPA entities are packages as a separate jar or included into the application. Its a runtime framework and in runtime classes can be loaded from the jar (it should reside in BOOT-INF/lib or 'directly' from the *.class files in the spring boot artifact.
Now there is a rule in spring boot, that says that it will scan for beans (including entities) only in the package where your "main" class resides or under it. This is done in order to avoid long process of analysis of, say, third-party classes that you might use. These third-party classes are usually not spring aware at all, at certainly do not contain any spring beans.
Example:
Say, you place your "main" class (the one annotated with #SpringBootApplication) in the package: com.mycompany.myapp
In this case, the following packages will be scanned (just a couple of examples):
com.mycompany.myapp
com.mycompany.myapp.web
com.mycompany.myapp.services.bl
com.mycompany.myapp.whatever.doesnt.matter
...
The following packages won't be scanned however (again, examples, not the full list):
com.mycompany
com.anothercompany
org.hibernate
If you want to to "alter" this default rule and place the entities in the package that doesn't adhere this convention, for example com.mycompany.jpa.entities then you should indeed use #EntityScan annotation as our colleagues have already suggested.
You can read about this topic here. You might also need to get familiar with #EnableJpaRepositories if you're using spring data but, while related, its a different topic.
In my case I had this problem, and after importing the library in the application's pom.xml, in the SpringBoot Project Main class, insert an #EntityScan annotation with the first package and *. Like this: #EntityScan ("br.*")

Spring Batch Project with Annotation Integrated with Spring Batch Admin

I have a Spring Batch Project which uses annotation based configurations and is a working code by itself. I now want to integrate this with a new Spring Batch Admin project.
I tried some solutions available/answered in the blogs, like adding dependency of batch project to the batch admin project and modifying the META-INF/spring/batch/servlet/override/context-config.xml file to point to the batch project config file.
i.e. . The com.sample.springbatch.job package is present in the Spring Batch project.
However, I am not successful with the integration.
Can anybody point me to or suggest a solution where Spring Batch Project - Annotation Based is integrated with Spring Batch Admin project.
Thank you!
Sonali
I tried this with Batch Admin 2.0.0, you don't want to use #EnableBatchProcessing which is already provided with Spring Batch Admin rather you may use #EnableBatchAdmin. I've added the code in github

Spring Annotation-based Project Templates

I am new to Spring. I am learning it from different sources. Spring Recipes, Spring In Action and Spring documentation. According to Spring 3.+, XML configuration can be ignored at all. This is good for me as a beginner.
Problem:
I am using Spring Tool Suite, is there a Spring Web project template that starts with annotations only? All the project templates I have found use XML configuration. I don't even know where to put my DispatcherServlet. I don't know where to put my controllers.
I also had the same problem when Starting out with Spring to find only annotation based templates. Then I found this from John Thompson. This project is completely annotation based and the only xml file involved is pom.xml
I recommend you to run through Spring Guides - they are up to date and use annotation based configuration.
This is guide how to make a restfull web service using spring-boot. It has description how to made project with maven, gradle or STS.
The official recommendation is to base all new projects on Spring Boot which is XML-less out of the box.
STS offers a nice integration with the Spring Initializr service: just go to "New -> Spring Starter Project", fill in a few fields like project name etc. and tick the boxes next to modules you're interested in.

Is it possible to use Spring within Eclipse plugins?

Is it possible to use a Spring container for DI from inside Eclipse plugins?
I'm wondering because I know that Eclipse causes a lot of issues with class loading, looking up things within the plugin, etc.
The plugin is intended to be distributed as a JAR.
Yes but you will need Spring DM http://www.springsource.org/osgi
The answer is yes. You can use Spring DM, but you don't have to. It is probably better with it.
I did it without Spring DM and the main concern is class loading issues (not sure if Spring DM solves them, but I guess it should). Assuming you bundle the Spring JAR in a separate plugin with dependencies, you will need to load the context with the class loader of the invoking plugin .
Example:
Plugin A - your functional plugin
Plugin B - The Spring lib plugin exporting the spring packages
Plugin A depends on B. When plugin A starts, it will load the application context, when invoking this load, you will need to do something like:
Thread.currentThread().setContextClassLoader(PluginAActivator.class.getClassLoader())
So that the loading of the classes will happen under your own class loader. Now you can use a ClassPathXmlApplicationContext to load configuration XMLs from your class path.
One small note: the default ClassPathXmlApplicationContext validates your XMLs upon loading. You may want to disable it or point your XMLs to a local schema (rather than the standard Spring schema on springframework.org), otherwise, you will connect to the internet to download the schema files upon loading and working offline will fail.
do you have a code example for your post?
This would be great, since I´m hanging around with this for a while.
Cheers!