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. For Spring Boot related questions, also include the tag [spring-boot].
spring
21,925
questions
781
votes
22
answers
759k
views
Why is my Spring @Autowired field null?
Note: This is intended to be a canonical answer for a common problem.
I have a Spring @Service class (MileageFeeCalculator) that has an @Autowired field (rateService), but the field is null when I try ...
110
votes
14
answers
109k
views
Why does Spring MVC respond with a 404 and report "No mapping found for HTTP request with URI [...] in DispatcherServlet"?
I'm writing a Spring MVC application deployed on Tomcat. See the following minimal, complete, and verifiable example
public class Application extends ...
52
votes
4
answers
41k
views
Spring JSF integration: how to manage a bean and inject a Spring component/service?
I understand that a managed bean works like a controller, because your only task is "link" the View Layer with Model.
To use a bean as a managed bean I must declare @ManagedBeanannotation, doing ...
75
votes
1
answer
154k
views
What is a NoSuchBeanDefinitionException and how do I fix it?
Please explain the following about NoSuchBeanDefinitionException exception in Spring:
What does it mean?
Under what conditions will it be thrown?
How can I prevent it?
This post is designed to be a ...
210
votes
11
answers
151k
views
Spring @Transaction method call by the method within the same class, does not work?
I am new to Spring Transaction. Something that I found really odd, probably I did understand this properly.
I wanted to have a transactional around method level and I have a caller method within the ...
2593
votes
30
answers
1.2m
views
What's the difference between @Component, @Repository & @Service annotations in Spring?
Can @Component, @Repository, and @Service annotations be used interchangeably in Spring or do they provide any particular functionality besides acting as a notation device?
In other words, if I have a ...
458
votes
16
answers
610k
views
Downloading a file from spring controllers
I have a requirement where I need to download a PDF from the website. The PDF needs to be generated within the code, which I thought would be a combination of a freemarker and a PDF generation ...
342
votes
10
answers
570k
views
Spring Boot configure and use two data sources
How can I configure and use two data sources?
For example, here is what I have for the first data source:
application.properties
#first db
spring.datasource.url = [url]
spring.datasource.username = [...
27
votes
11
answers
76k
views
CORS issue - No 'Access-Control-Allow-Origin' header is present on the requested resource
I have created two web applications - client and service apps.The interaction between client and service apps goes fine when they are deployed in same Tomcat instance.
But when the apps are deployed ...
390
votes
6
answers
181k
views
Difference between applicationContext.xml and spring-servlet.xml in Spring Framework
Are applicationContext.xml and spring-servlet.xml related anyhow in Spring Framework?
Will the properties files declared in applicationContext.xml be available to DispatcherServlet?
On a related note, ...
38
votes
7
answers
25k
views
What causes "java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute"?
This is meant to be an extensive canonical question & answer post for these types of questions.
I'm trying to write a Spring MVC web application where users can add movie names to an in-memory ...
49
votes
2
answers
12k
views
When is it necessary or convenient to use Spring or EJB3 or all of them together?
I'm a little confused by the mixed use of JSF2+Spring+EJB3 or any combination of those. I know one of the Spring principal characteristics is dependency injection, but with JSF managed beans I can use ...
136
votes
25
answers
481k
views
How to configure CORS in a Spring Boot + Spring Security application?
I use Spring Boot with Spring Security and Cors Support.
If I execute following code
url = 'http://localhost:5000/api/token'
xmlhttp = new XMLHttpRequest
xmlhttp.onreadystatechange = ->
if ...
352
votes
3
answers
469k
views
Understanding Spring @Autowired usage
I am reading the spring 3.0.x reference documentation to understand Spring Autowired annotation:
3.9.2 @Autowired and @Inject
I am not able to understand the below examples. Do we need to do ...
54
votes
4
answers
91k
views
Dynamic spring data jpa repository query with arbitrary AND clauses
I'm using Spring data jpa repositories, Got a requirement to give search feature with different fields. Entering fields before search is optional.I have 5 fields say EmployeeNumber, Name, Married,...