There is any chance to use spring-boot-starters in regular spring project? I have, big trouble with configuration Spring Social project. I've already configured many others things and I don't want to move my project to Spring Boot just for one library.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-social-facebook</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-social-linkedin</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-social-twitter</artifactId>
</dependency>
There is any possibility to use Spring Boot goods in regular Spring project? I'm quite confused about Spring Boot, as I read that project helps to quick start project on Spring without making many configs, there are some other pros against regular Spring Project?
But my main question in this thread is: "how to use spring-boot-starters in regular spring project?"
There is independent project (I can't put more than 2 links, so, others you can find in comment):
http://projects.spring.io/spring-social-facebook/
And there is a spring social quick start, which will help you to start with it:
https://github.com/spring-projects/spring-social-samples/tree/master/spring-social-quickstart
spring-social-starter have only maven dependencies. For example, spring-boot-starter-social-facebook contains this in pom.
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-facebook</artifactId>
</dependency>
</dependencies>
You can add this without dependencies from org.springframework.boot package in your pom for using it without spring-boot functionality.
Related
I upgraded hibernate-core-jakarta version. I get this error when trying to run the project.
The project includes; Java17, spring boot 2.7.x
java.lang.NoClassDefFoundError: org/springframework/aot/hint/TypeHint$Builder
error logs
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core-jakarta</artifactId>
<version>5.6.14.Final</version>
</dependency>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>jakarta.transaction</groupId>
<artifactId>jakarta.transaction-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.angus</groupId>
<artifactId>jakarta.mail</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>6.0.3</version>
</dependency>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>6.0.0</version>
</dependency>
With Spring Boot 2.7, you should use the normal hibernate-core dependency, not hibernate-core-jakarta. You should also let Spring Boot manage the versions of your dependencies, not specify them yourself.
You seem to have added multiple dependencies using the jakarta.* package namespace, which do not work with Spring Boot 2.7, you would need to upgrade to Spring Boot 3.0 if you want to use Jakarta EE 9 libraries (and again, then you should still let Spring Boot manage your versions instead of specifying them yourself).
The same goes for Spring. Spring Boot 2.7 uses Spring 5.3, it cannot use Spring 6. This is likely the immediate cause of the "java.lang.NoClassDefFoundError: org/springframework/aot/hint/TypeHint$Builder".
TL;DR, stop managing your versions like this, and let Spring Boot manage them for you.
If you want to use Jakarta EE 9+ (using the jakarta.* package namespace) and Spring 6 dependencies, you have to upgrade to Spring Boot 3, not upgrade individual dependencies yourself.
I am trying to inject the spring-boot-starter-security dependency in a simple spring boot application (Maven). I tried to copy this dependency from the "Securing a Web Application" tutorial from the actual Spring website, I also tried to implement it together with the spring security test dependency and thymeleaf spring security dependency.
So here are the dependencies that get the error "not found":
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
And here it is the full pom file:
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.3.1.RELEASE
com.homehero
homehero
0.0.1
war
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
I feel the need to thank y'all in advance and sorry if I'm missing something really stupid, I really hope I'm not!
I solved the problem.
Long story short, a friend of mine suggested doing a new project with Spring Initializer and this time add from the beginning the "Spring Boot Security" dependency. After that, I just needed to compare the pom files. The only difference was that the new project had a:
<scope>test</scope>
line. I added that to my initial project and the first dependency did not get the error anymore. The second dependency was the Thymeleaf spring security one, in order to fix this one I added:
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
To my pom file.
So this is how the dependencies look together now:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
That's it, thank you for all the answers you guys also provided.
Take a look in the version of parent POM.xml file. When I've changed the version to 2.0.0 my project founds the dependency.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
I had the same problem. follow these steps:
1- Delete the dependencies that are not found.
2- Sync your project.
3- Add the dependencies.
4- sync the project again.
it worked for me hope works for everyone else:)
Not sure how you are creating project.I can tell you simple solution,which is to go to Spring Initializer ,link for which is https://start.spring.io/
There you can add all your required dependencies and then just click on Generate,which will download your project.You can just import the project in your IDE and run maven build.I tried with Spring boot version 2.3.1 only as you mentioned and it worked for me and should work for you.
Also,I would suggest you to user Intellij IDE,which comes with maven support by default,so it will make things easy for you.You can download Intellij free edition from here:
https://www.jetbrains.com/idea/download/#section=windows
Hope it will help you.
I am using spring-boot 2.0.5.RELEASE with Jhipster 5.3.3, my pom is as follow :
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.github.jhipster</groupId>
<artifactId>jhipster-dependencies</artifactId>
<version>${jhipster-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- jhipster-needle-maven-add-dependency-management -->
</dependencies>
</dependencyManagement>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
...
Now as i learned that spring data has support released for MongoDB4 transaction management, i wanna give it a try, cause it sounds very cool !
Based on spring reference documentation : https://docs.spring.io/spring-data/mongodb/docs/2.1.0.RELEASE/reference/html/#dependencies
using spring data mongodb 2.1.0.RELEASE with spring boot is as easy as adding the BOM of releasetrain. Which i did, and my pom become :
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.github.jhipster</groupId>
<artifactId>jhipster-dependencies</artifactId>
<version>${jhipster-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- jhipster-needle-maven-add-dependency-management -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain</artifactId>
<version>Lovelace-RELEASE</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
But this didn't bring any of spring data mongodb 2.1.0 jars, only the pom of the releasetrain lovelace. Maven only download the pom of the releasetrain and keep downloading the spring data mongodb 2.0.10 that is shipped with spring boot 2.0.5.
add spring-data-mongodb in your pom.xml too
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
</dependency>
I find the way to do it, since i am using Jhipster as a parent to my project pom, i hade to declare the lovelace dependency management before the Jhipster one, so my pom become :
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain</artifactId>
<version>Lovelace-RELEASE</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>io.github.jhipster</groupId>
<artifactId>jhipster-dependencies</artifactId>
<version>${jhipster-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
Maven then will download the version of spring data mongodb specified in depenedncy management of lovelace.
I had to read the spring boot reference guide to understand that.
I'am trying to write a spring security test as described here http://docs.spring.io/spring-security/site/docs/4.0.x/reference/htmlsingle/#test-mockmvc-setup. I need to import SecurityMockMvcConfigurers as a static import, but my IDE does not find the class.
My pom.xml looks as follows:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.M2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Spring Boot 1.4.0.M2 imports Spring Security 4.0.4.RELEASE. I' can't find the class in this release. Which additional dependency do I need? Or what else I haven't considered?
The missing dependency was:
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<version>4.0.4.RELEASE</version>
</dependency>
The required dependency for the org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers class is the org.springframework.security:spring-security-test dependency.
The question is tagged Spring Boot and Spring Boot provides the dependency as a managed dependency in the spring-boot-starter-parent pom.
Your pom inherits very probably from spring-boot-starter-parent.
So above all don't specify a version without a very good reason and use simply the version inherited from the parent.
That is enough :
<dependencies>
...
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
...
<dependencies>
For example with Spring Boot 2.0.0.M5, the managed version is
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<version>5.0.0.M5</version>
</dependency>
The M5 is not just chance.
These are designed to work "better" together.
Note that org.springframework.boot:spring-boot-starter-test dependency doesn't pull the spring-security-test dependency.
In case you don't use Spring Boot, you should endeavor to specify a spring-security-test version conform to the Core Spring version used by the application.
The class SecurityMockMvcConfigurers is included in
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
In other releases SecurityMockMvcConfigurers may not exist.
However there is a class MockMvcConfigurer, may be you can work with this instead ?
regarding : but this dependency does not contain the corresponding class.
Yes you are right that class is no inluded in the jar.
So I think you have to use what is there.
Anyway, the class is rather simple and the sourcecode is here :
SecurityMockMvcConfigurers
Just copy the code in your own class and you are done.
I have been trying to integrate Struts 2 with Zero Configuration, Spring, Hibernate and Maven.
But, what I think there must be something which I am missing in integration and it must be related to the configuration of Maven's Pom.xml:
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.1.8.1</version>
</dependency>
<!-- Struts 2 + Spring plugins -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>2.1.8.1</version>
</dependency>
<!-- MySQL database driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.9</version>
</dependency>
<!-- Spring framework -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>2.5.6</version>
</dependency>
<!-- Hibernate core -->
<dependency>
<groupId>asm</groupId>
<artifactId>asm-all</artifactId>
<version>3.3</version>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.3</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.7.Final</version>
</dependency>
<!-- Hibernate core library dependency start -->
<!-- Hibernate core library dependency end -->
<!-- Hibernate query library dependency start -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>2.1.8.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
</dependency>
As when I use this configuration it gives me an error
java.lang.NoSuchMethodError: com.opensymphony.xwork2.util.finder.UrlSet.<init>(Lcom/opensymphony/xwork2/util/finder/ClassLoaderInterface;Ljava/util/Set;)V
And instead of opensymphony XWork libaray I use dependency of
<dependency>
<groupId>org.apache.struts.xwork</groupId>
<artifactId>xwork-core</artifactId>
<version>2.3.8</version>
</dependency>
It throws me this exception
Caused by: Unable to load configuration. - [unknown location]
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58)
When you upgrade the version of Struts2, you have to update the libraries requires by your application to the target version. Each distro of Struts2 supplied with the corresponding set of libraries in the lib folder that are compatible with the version of distro. If you use maven to resolve and fetch the dependencies you should consider the artifact struts2-core.
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.8</version>
</dependency>
It will fetch all required dependencies for this artifact, other dependencies, such as plugins you need to add separately. Use the same version targeted to plugins. For example to add a convention plugin use
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>2.3.8</version>
</dependency>
The targeted version number I've chosen 2.3.8 but it's possibly incompatible with the other features i.e. Hibernate and Spring which versions need to upgrade separately by adding corresponding artifacts to the dependencies.
And finally and most time consuming is changes to the source code of the project, update the configuration files according to newer DTDs , API changes, fix deprecations. For this purpose consider reading the release notes.
Also see the example of developing a Maven project: Create Struts 2 Web Application Using Maven To Manage Artifacts and To Build The Application.