Why is my H2 database Spring config not working? - spring

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.

Related

What is the web dependency in the Kotlin Spring Boot tutorial?

In the Kotlin Spring Boot tutorial it asks you to include the web dependency, like this:
but in the actual Spring Boot initializr, I don't see that:
What's the web dependency that's required? Is it Spring Web Starter? Is this tutorial out of date and/or obsolete?
spring web starter is the one you need to select it's what they refer to in the tutorial.
its the full name for it.
if you look in the tutorial they later show the pom.xml There you can see that they have declared the:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
and the tuturial still seems okey so go for it.

JpaStateMachineRepository not available in Spring StateMachine 2.0.0

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.

maven dependencies for writing Spring AOP programs?

I am trying to learn Spring AOP programming using Spring 5. I am going through online materials.
I came to know that AOP is a concept, similar to OOP; and with AOP,OOPs becomes more powerful.
Now, I am trying to do some hands-on coding for AOP with Spring framework, version 5.
I am going to use maven as the build tool.
I am not clear on what are the various dependencies that we have to use in pom.xml, for example do we need to use: spring-aop , spring-aspects, aspectjetc.
Can anyone guide me what are the various maven dependencies that we have to add in pom.xml to be able to write using maven tool, Spring 5 AOP programs?
Thanks in advance
Its very simple, in order to work spring With AOP, You need aspectjweaver Library existe on the classpath of your application (version 1.6.8 or later).use this dependency to achieve that
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.13</version>
</dependency>
As they mention in docs
To enable #AspectJ support with Java #Configuration add the
#EnableAspectJAutoProxy annotation:
You can find more info here
The only spring dependency to make something work with AOP is the famous spring-context :
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
If you want a working example check my project in github which contains basic Maven AOP example based on spring
If you are trying to use CGLIB proxies in Spring without Spring Boot (and any starter dependencies of Spring Boot) then you need aspectjweaver besides spring-context, spring-aop dependencies.
Be careful not to add any of the dependencies if they already exist among your Maven dependencies - adding the same dependency with multiple versions may lead to a failing build.

Spring Boot 1.5.9 - Jaxb2Marshaller

Trying to learn Spring Boot. Taking existing Spring application and rebuilding it in a new boot project. One of my clasess relies upon a dependency org.springframework -> spring-oxm which is for the Jaxb2Marshaller.
In my Spring Boot project when I add this dependency
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>3.2.2.RELEASE</version>
</dependency>
When I add the above to my POM it never pulls the jar in so I cannot import the Jaxb2Marshaller. I believe Spring Boot logic is keeping this from being pulled in because of the version. I tried other versions, but no luck. What is the proper way to pull in this spring dependency with the right version?

Is Mybatis supported with Spring 4.x?

I tried mybatis-spring 1.2.2 with mybatis 3.2.5 and Spring version 4.1.0.Release and it appears like it is not supported.
mybatis-spring 1.2.2 spring contains org.springframework.core.MethodParameter class however, getContainingClass() is not present.
I am getting the exception:
java.lang.NoSuchMethodError: org.springframework.core.MethodParameter.getContainingClass()
Any idea is I could use Mybatis with Spring 4x at all? (even ibatis seems to be unsupported)
Looking in the pom.xml of the Spring MyBatis here I can see that the project itself depends on Spring 3.2.9:
...
<spring.version>3.2.9.RELEASE</spring.version>
...
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
<scope>provided</scope>
</dependency>
So, based on that I wouldn't be surprised if I would get an exception like the one you are getting in my project and I would have to say that "no", it's not supported.
We are using MyBatis v3.2.7 with Spring v4.0.6 and so far we have not seen any issues. Since Spring usually maintains the backward compatibility, it usually works.
However, I am not sure (as of this writing) if it is totally supported in Spring v4.1.x.

Resources