Questions tagged [spring]

The Spring Framework is an open-source framework for application development on the Java platform. At its core is rich support for component-based architectures, and it currently has over twenty highly integrated modules.

The Spring Framework is an open-source application framework for the Java platform.

Spring is a non-invasive, versatile, robust framework.

Spring framework complements the Java EE APIs but is not a replacement for Java EE. It reduces most boilerplate code, reducing the burden on developers.

Spring provides services and functionalities across the application domain, including a core Inversion of Control container, technology-agnostic data-access and MVC layers, extensive AOP support, task scheduling, and various integration patterns designed to make distributed system development more uncomplicated and more straightforward. While some Spring modules are simple wrappers and helpers over the Java EE specifications, most go far beyond the Java EE specification.

The latest Spring Framework Reference Documentation can be found here.

Spring version history:

Version    Date   
5.2.x    Dec, 2020
5.1.x    Sep, 2018 
5.0.x    Sep, 2017 
4.3.x    Jun, 2016 
4.2.x    Jul, 2015 
4.1.x    Sep, 2014 
4.0.x    Dec, 2013 
3.2.x    Dec, 2012 
3.1.x    Dec, 2011 
3.0.x    Dec, 2009 
2.5.x    Nov, 2007 
2.0.x    Jun, 2006 
1.2.x    Mar, 2005 
1.1.x    Jul, 2004 
1.0.x    Feb, 2004 

Frequently Asked Questions

People often ask about the following Spring topics:

Guides:

Video tutorial on Spring Framework

Examples:

Blog:

Related tags

More information:

Official Logo:


Spring logo

208702 questions
260
votes
50 answers

intellij incorrectly saying no beans of type found for autowired repository

I have created a simple unit test but IntelliJ is incorrectly highlighting it red. marking it as an error No beans? As you can see below it passes the test? So it must be Autowired?
Robbo_UK
  • 11,351
  • 25
  • 81
  • 117
258
votes
9 answers

How do I mock an autowired @Value field in Spring with Mockito?

I'm using Spring 3.1.4.RELEASE and Mockito 1.9.5. In my Spring class I have: @Value("#{myProps['default.url']}") private String defaultUrl; @Value("#{myProps['default.password']}") private String defaultrPassword; // ... From my JUnit test,…
Dave
  • 15,639
  • 133
  • 442
  • 830
258
votes
6 answers

How to set an "Accept:" header on Spring RestTemplate request?

I want to set the value of the Accept: in a request I am making using Spring's RestTemplate. Here is my Spring request handling code @RequestMapping( value= "/uom_matrix_save_or_edit", method = RequestMethod.POST, …
edaklij
  • 4,121
  • 11
  • 31
  • 43
254
votes
23 answers

Why does my Spring Boot App always shutdown immediately after starting?

This is my first Spring Boot code. Unfortunately, it always shuts down. I was expecting it to run continuously so that my web client can get some data from the browser. package hello; import org.springframework.boot.*; import…
johnsam
  • 4,192
  • 8
  • 39
  • 58
253
votes
4 answers

Difference between @Mock, @MockBean and Mockito.mock()

When creating tests and mocking dependencies, what is the difference between these three approaches? @MockBean: @MockBean MyService myservice; @Mock: @Mock MyService myservice; Mockito.mock() MyService myservice = Mockito.mock(MyService.class);
Doug
  • 5,661
  • 2
  • 26
  • 27
252
votes
33 answers

Spring boot - Not a managed type

I use Spring boot+JPA and having a problem while starting the service. Caused by: java.lang.IllegalArgumentException: Not an managed type: class com.nervytech.dialer.domain.PhoneSettings at…
user1578872
  • 7,808
  • 29
  • 108
  • 206
249
votes
8 answers

How do you get current active/default Environment profile programmatically in Spring?

I need to code different logic based on different current Environment profile. How can you get the currently active and default profiles from Spring?
Bobo
  • 8,777
  • 18
  • 66
  • 85
246
votes
15 answers

Get list of JSON objects with Spring RestTemplate

I have two questions: How to map a list of JSON objects using Spring RestTemplate. How to map nested JSON objects. I am trying to consume https://bitpay.com/api/rates, by following the tutorial from http://spring.io/guides/gs/consuming-rest/.
Karudi
  • 2,692
  • 3
  • 18
  • 19
245
votes
16 answers

Getting Spring Application Context

Is there a way to statically/globally request a copy of the ApplicationContext in a Spring application? Assuming the main class starts up and initializes the application context, does it need to pass that down through the call stack to any classes…
Joe Skora
  • 14,735
  • 5
  • 36
  • 39
242
votes
4 answers

javax.transaction.Transactional vs org.springframework.transaction.annotation.Transactional

I don't understand what is the actual difference between annotations javax.transaction.Transactional and org.springframework.transaction.annotation.Transactional? Is org.springframework.transaction.annotation.Transactional an extension of…
stamis
  • 2,545
  • 2
  • 15
  • 9
235
votes
4 answers

How to POST form data with Spring RestTemplate?

I want to convert the following (working) curl snippet to a RestTemplate call: curl -i -X POST -d "email=first.last@example.com" https://app.example.com/hr/email How do I pass the email parameter correctly? The following code results in a 404 Not…
sim
  • 3,552
  • 5
  • 23
  • 23
234
votes
16 answers

Unable to find a @SpringBootConfiguration when doing a JpaTest

I'm trying to run a simple Junit test to see if my CrudRepositories are indeed working. The error I keep getting is: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your…
Thomas Billet
  • 2,381
  • 2
  • 13
  • 13
230
votes
14 answers

Trigger 404 in Spring-MVC controller?

How do I get a Spring 3.0 controller to trigger a 404? I have a controller with @RequestMapping(value = "/**", method = RequestMethod.GET) and for some URLs accessing the controller, I want the container to come up with a 404.
NA.
  • 6,451
  • 9
  • 36
  • 36
228
votes
4 answers

@RequestParam in Spring MVC handling optional parameters

Is it possible for a Spring controller to handle both kind of requests? 1) http://localhost:8080/submit/id/ID123432?logout=true 2) http://localhost:8080/submit/id/ID123432?name=sam&password=543432 If I define a single controller of the kind: …
luksmir
  • 3,104
  • 5
  • 22
  • 38
227
votes
6 answers

Difference between using bean id and name in Spring configuration file

Is there any difference between using an id attribute and name attribute on a element in a Spring configuration file?
Bear Bibeaults