JpaStateMachineRepository not available in Spring StateMachine 2.0.0 - spring-statemachine

After creating project via spring Initializr https://start.spring.io/
with option Statemachine checked.
If I try to autowaire JpaStateMachineRepository then I get
JpaStateMachineRepository cannot be resolved to a type.
There is no import option. I have spring-statemachine-bom in my pom and I beleive it has spring-data-jpa already dependancy covered already.
I am migrating from 1.2.8 to 2.0.0. Please help.

start.spring.io only adds spring-statemachine-starter which effectively only adds spring-statemachine-autoconfigure. spring-statemachine-bom only adds dependency management, not dependencies itself.
You just need to import below dep manually:
<dependency>
<groupId>org.springframework.statemachine</groupId>
<artifactId>spring-statemachine-data-jpa</artifactId>
</dependency>
We're probably going to add more starters for usual use cases. JPA seem to be one of those which could have its own statemachine related starter.

Related

How to find Spring Boot auto-configuration classes that are activated by adding a specific starter project to pom?

How Spring Boot auto-configuration classes are activated based on the maven starter projects that are included in project pom.xml as dependencies?
for example, by adding spring-boot-starter-security to pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
class SecurityAutoConfiguration is activated. how does this happen? How SecurityAutoConfiguration is related to spring-boot-starter-security?
the starter project themselves are completely empty, there is no java code in these starter projects, and just a couple of dependencies is defined in pom.xml. I want to know exactly what happens when I add a starter project to my Spring Boot project and exactly what configurations are applied.
Autoconfiguration is one, or maybe the main one, feature of SpringBoot
Basically, depending on certain conditions, some configurations or/and beans are made available.
In your case here is what happens :
spring-boot-starter-security, as other starters, is just here to make some others dependencies available for your project, particulary spring-security-config which itself, has a dependency on spring-security-core
If your looking at the code source of SecurityAutoConfiguration you can see that is configuration class depends on the availabality of the class DefaultAuthenticationEventPublisher, which is true as now you have a (transitive) dependency on spring-security-core.
This SecurityAutoConfiguration class is listed as a Autoconfiguration class inside the config file org.springframework.boot.autoconfigure.AutoConfiguration.imports (spring.factories for some previous Spring Boot version) of the spring-boot-autoconfigure project, which make it active for your application.
Here you can find the documentation :
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.developing-auto-configuration.understanding-auto-configured-beans
You can find it here - https://www.baeldung.com/spring-boot-security-autoconfiguration
Basically, either property for the starter can be disabled or exclude specific auto configuration from #springboot(exclude = SecurityAutoConfiguration.class
)

Why is my H2 database Spring config not working?

I am always getting java.lang.NoSuchMethodError: org.springframework.orm.jpa.JpaTransactionManager$JpaTransactionObject.setReadOnly(Z)V
I do not know why.
I use H2 database in memory. According to spring there is no configuration necessary. I just include the dependency in my maven POM . But when I call the database it gives me this error.
public interface ClientRepository extends CrudRepository<Client, Long> {
I know a lot had this error before but I cannot see any mistake on my side. According to spring it should work out of the box. Just add maven dependency. Nothing more. So where is my error.
It seems that if you mix Spring boot dependencies and Spring framework dependencies maybe this could cause a problem. I really do not know. I removed this dependency
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.1.3.RELEASE</version>
</dependency>
It was not Spring boot . So I would not need it anyway. I think Spring boot will never ever need any Spring framework dependency I guess.
Also versions could maybe be an issue. I did not include any version. Because Spring boot should then just take the latest one. Right ? But now I have versions. Maybe this was also an issue.

Spring Boot project depending on a spring project

fair warning: I am new to Spring and maven.
The project:
The client has provided us with a web project that uses jsp to render front ends and uses spring-context only to manage some of their classes as Spring Beans. This project uses xml configuration. Here is the maven section that includes the spring-context:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.8.RELEASE</version>
</dependency>
Our job is to create an api layer for this project to open up access to the project's resources. The plan is to create a modern Spring Boot api using the spring-boot-web starter.
The problem:
The jsp project is split up into sub-modules. We are trying to take their business logic submodule as a maven dependency in our api project (it defines it's own spring context). The first problem that we have faced occurs when we simply add the module from the jsp project as a dependency in our api project. The spring boot initialization process provides no log feedback and hangs but does not exit (It runs fine when the dependency is not included). When crawling through with a debugger I have found that it is loading configuration files that are in the business module. My thinking is that one of the api's configuration files are getting overwritten which is breaking spring's logging and other behaviors.
The other more general problem is that I don't know if I can use the beans provided in the business logic module in my modern version of spring.
So the question is:
Is there a proper way to use beans defined in a dependent spring project?

Up to date Spring boot version in submodule & different Spring version in parent

I am trying to create the Spring Boot application which is submodule of our project's parent pom (which depends on our internal framework which locks down spring dependency versions - as of now we are at 4.2.4-RELEASE)
If I specify the latest Spring Boot version (1.4.1-RELEASE) which depends on spring 4.3.3-RELEASE, I am facing conflicts
One of them is following error:
Caused by: java.lang.NoClassDefFoundError:
org/springframework/beans/factory/ObjectProvider
This class was introduced in 4.3, which explains that error
Is there a way how to keep my Spring Boot dependencies up-to-date without updating Spring versions in internal framework?
You're supposed to keep all your Spring dependencies in sync by making spring-boot-starter-parent your parent.
That sets up all the <dependencyManagement> for you, and you should not then be using <version> when you pull in specific dependencies.
If you need to override a version managed by the parent, there should be a property that you can change, named e.g. logback.version, spring-security.version, etc.
You can also stop one of your dependencies from overriding the versions of its dependencies by using <excludes> to remove the transitive dependency entirely, and ensuring you pull it in from elsewhere. This is a much more brittle though.
You could also try importing spring-boot-dependencies into your dependencyManagement, but you're probably making more work for yourself trying to add your existing projects as the Boot project's parent, rather than as dependencies.

jaxws-spring maven dependency is for what purpose

I have the following maven dependecy in my project.
<dependency>
<groupId>org.jvnet.jax-ws-commons.spring</groupId>
<artifactId>jaxws-spring</artifactId>
<version>1.8</version>
</dependency>
Question:
Is this Spring Webservices project?
If not what this dependency is for?
Thanks for your help.
It's a project combining JAX-WS and Spring. Basically it gives you the wss namespace that you might be using in your application context to expose JAX-WS providers as web services. It isn't mandatory but it can be a convenience as it allows you to easily have dependency injection in your servlets although there are other ways to get this. Unfortunately, the last time I was using it I noticed that it was depending on some pretty old spring libraries (pre 3.x) and didn't seem to be updated in some time.

Resources