Questions tagged [spring-3]
Version 3.x of the Spring Framework, use [tag:spring] for general Spring related questions.
771
questions
724
votes
15
answers
354k
views
Difference between <context:annotation-config> and <context:component-scan>
I'm learning Spring 3 and I don't seem to grasp the functionality behind <context:annotation-config> and <context:component-scan>.
From what I've read they seem to handle different ...
352
votes
3
answers
468k
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 ...
224
votes
6
answers
401k
views
When use ResponseEntity<T> and @RestController for Spring RESTful applications
I am working with Spring Framework 4.0.7, together with MVC and Rest
I can work in peace with:
@Controller
ResponseEntity<T>
For example:
@Controller
@RequestMapping("/person")
@Profile("...
157
votes
3
answers
159k
views
What's the difference between <mvc:annotation-driven /> and <context:annotation-config /> in servlet?
I am migrating from Spring 2.5 to Spring 3.
They have introduced <mvc:annotation-driven /> which does some black magic. This is expected to be declared in servlet configuration file only.
In ...
123
votes
7
answers
113k
views
How to get a method's annotation value from a ProceedingJoinPoint?
I have below annotation.
MyAnnotation.java
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
}
SomeAspect.java
public class SomeAspect{
@Around("...
67
votes
2
answers
90k
views
How to register Spring @Configuration annotated class instead of applicationContext.xml file in web.xml?
I am using jsf and spring together in web application. I have configured datasource and session factory in one configuration class which uses annotations like @Configuration, @ComponentScan etc. I don'...
59
votes
5
answers
143k
views
How to set 'Content-Disposition' and 'Filename' when using FileSystemResource to force a file download file?
What is the most appropriate, and standard, way to set the Content-Disposition=attachment and filename=xyz.zip using Spring 3 FileSystemResource?
The action looks like :
@ResponseBody
@...
57
votes
6
answers
43k
views
Add attributes to the model of all controllers in Spring 3
Every single view in my Spring 3 app has a set of attributes they can rely on. So the first line of every controller is something like:
ControllerHelper.addDefaultModel(model, personManager, request)...
56
votes
2
answers
46k
views
When use AbstractAnnotationConfigDispatcherServletInitializer and WebApplicationInitializer?
I am working with Spring 4.0.7
I did a research about configure Spring MVC through JavaConfig.
Practically until yesterday I have seen two configurations using these two options
extends ...
56
votes
12
answers
72k
views
Encoded slash (%2F) with Spring RequestMapping path param gives HTTP 400
This is not a duplicate referenced question, because it is Spring specific. Whoever added that (3 years after the fact!) didn't bother to read the question or comment thread to see what the real ...
54
votes
2
answers
33k
views
Benefits of JavaConfig over XML configurations in Spring?
Earlier the configurations used to be in hard coded in the code, later it was externalized to .property files (for sake of avoiding hard coded values, avoiding changing code for the sake of changing ...
42
votes
7
answers
52k
views
EJB 3.1 or Spring 3.. When to choose which one?
EJB achieved many improvements in 3.x versions, Spring is also commonly used and version 3 is a good alternative.
There are many articles on web, but no exact comparison about ejb3x versus spring3x.. ...
41
votes
3
answers
167k
views
Multiple scenarios @RequestMapping produces JSON/XML together with Accept or ResponseEntity
I am working with Spring 4.0.7
About Spring MVC, for research purposes, I have the following:
@RequestMapping(value="/getjsonperson",
method=RequestMethod.GET,
...
36
votes
6
answers
71k
views
Can @PathVariable return null if it's not found?
Is it possible to make the @PathVariable to return null if the path variable is not in the url? Otherwise I need to make two handlers. One for /simple and another for /simple/{game}, but both do the ...
33
votes
4
answers
57k
views
org.hibernate.HibernateException: No Session found for current thread
I'm getting the above exception with Spring3 and Hibernte4
The following is my bean xml file
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"...
33
votes
7
answers
53k
views
@EnableTransactionManagement annotation with 2 transaction managers
I am using @Configuration annotation for configuration of spring instead of xml file. I am configuring 2 datasources with different session factory and different transaction managers. I am stuck with ...
30
votes
10
answers
31k
views
A component named 'XXX' is already defined in this module in JBoss 7.1.1
I did not create the spring bean name with TimerServiceDispatcher in my application. But, the JBoss throw exception because of TimerServiceDispatcher is already defined in this module.
I don't know ...
28
votes
1
answer
33k
views
Can Spring MVC's REST framework accept query strings rather than PathVariables?
In all the tutorials and articles I have read regarding Spring 3's RESTful additions to Spring MVC, I have only ever seen one way for the use to pass in query data, via a @PathVariable, like so:
@...
27
votes
7
answers
38k
views
Spring's @Scheduled error : Only one AsyncAnnotationBeanPostProcessor may exist within the context
I am trying Spring 3's @Scheduled annotation . Here is my configuration (app.xml) :
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:...
26
votes
4
answers
66k
views
Spring 3 @ImportResource with multiple files
I'm trying to find the syntax for importing multiple spring xml context files using Spring 3 @ImportResource annotation.
I have tried using comma to separate the filenames as illustrated below but ...
25
votes
3
answers
36k
views
spring-security - where can I find the list of ALL security filters registered when I use the <http> element?
There are a default set of filters registered when we use the <http> element in our xml file. This mentions the ordering of filters (whichever we choose to apply), and just above that, it ...
25
votes
3
answers
83k
views
No AuthenticationProvider found for UsernamePasswordAuthenticationToken
my web.xml config is
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</...
23
votes
3
answers
45k
views
no declaration can be found for element 'mvc:annotation-driven'
I have the requirement of returning JSON/XML data from my controller.From what i found,I needed @ResponseBody in my method and for that I need <mvc:annotation-driven> enabled. I have tried all ...
23
votes
3
answers
20k
views
Reference an Annotated Spring Component in an XML Bean Definition
I am using an external library that requires that I configure it using an XML Bean definition; in the Bean definition I need to provide an external class with a Bean from my project. I am using spring ...
22
votes
1
answer
18k
views
@Autowired by constructor looks for beans by type. How to inject a bean by name to a constructor using autowired annotation
@Autowired by constructor looks for beans by type. How to inject a bean by name to a constructor using autowired annotation?
I have 2 beans of same type but I need to inject it to constructor of ...
22
votes
4
answers
13k
views
Why unit testing with Spring 3.1 WebMvcConfig fails?
From Spring 3.1, we can use JavaConfig more easily thanks to @Enable* annotations.
So I made a WebConfig to set WebMvc configuration, and tried to test it. But if I extends WebMvcConfigurerAdapter ...
21
votes
4
answers
32k
views
eventlisteners using hibernate 4.0 with spring 3.1.0.release?
These jars are both new released and have the latest solutions for Java EE applications. But I have a problem on specifiying hibernate listeners in hibernate.cfg.xml.
Before spring 3.1.0, ...
21
votes
1
answer
28k
views
Login/logout in REST with Spring 3
We are developing RESTful webservices with Spring 3 and we need to have the functionality of login/logout, something like /webservices/login/<username>/<password>/ and /webservices/logout. ...
21
votes
2
answers
28k
views
No persistence exception translators found in bean factory. Cannot perform exception translation
I'm getting following exception after migrating to Spring Framework 3.1.0 RC1 with Hibernate 4.0.0 CR7
2011-12-08/11:48:38.425/EST [Thread-17] ERROR Context initialization failed
org....
21
votes
3
answers
31k
views
Downloading Spring Jars without using Maven
How do you download Spring Framework jars if you can't stand Maven or any of the other build management tools. From what I can tell it seems you have to spend many frustrating hours on Google to find ...
20
votes
7
answers
82k
views
BeanFactory not initialized or already closed - call 'refresh' before accessing beans
I'm trying to add spring security to a regular JSF application. After repeated tries and I'm failing with the following error on tomcat bring-up.
Here is the entire stack trace. Any help is ...
20
votes
1
answer
19k
views
Need understanding of spring.handlers and spring.schemas
I have some questions derived from a problem that I have already solved through this other question. However, I am still wondering about the root cause. My questions are as follows:
What is the ...
20
votes
1
answer
36k
views
How to generate WADL for Spring REST Service
Hi I am working with Spring 3.5.0.Release. I want to generate a WADL for my spring rest service. Is their any functionality in Spring by which i can easily generate the WADL.
19
votes
2
answers
53k
views
Spring MVC: How to remove session attribute?
Example of using @SessionAttributes below. How to clear user session attribute after wizard finished ? In my example after returning to /wizard0 session attribute still exists. I've tried status....
18
votes
14
answers
28k
views
No Session found for current thread (Spring 3.1.X and Hibernate 4)
I'm trying to set up my project using Spring 3.1 and Hibernate 4. I've been following some tutorials online. I'm getting a strange error that according to the spring forums should have been fixed ...
17
votes
9
answers
24k
views
Spring conversion service - from List<A> to List<B>
I have registered a custom conversion service in a Spring 3 application. It works well for POJOs but it does not work on Lists.
For example, I convert from String to Role and it works fine, but not ...
17
votes
3
answers
62k
views
JDBCTemplate queryForMap for retrieving multiple rows [duplicate]
Can I use queryForMap if there are multiple rows returned by the query.
For a single row, the below code works fine.
public Map<String, Object> retrieveMultipleRowsColumns(String deptName){
...
17
votes
2
answers
21k
views
Elegant way to get Locale in Spring Controller [duplicate]
I'm looking for a cleaner way (in Spring 3.2) to get the current locale than explicitly calling LocaleContextHolder.getLocale() at the start of each Controller method. It has to be compatible with ...
17
votes
2
answers
13k
views
Is there any way to override a bean discovered by component scan?
I have a java configuration class providing fooBean directly and barBean by component scan.
@Configuration
@ComponentScan(basePackages = { "com.blah" })
public class Config {
@Bean
public ...
16
votes
5
answers
36k
views
difference between @Component and @Configuration in Spring 3
I came across two annotations provided by Spring 3 (@Component and @Configuration)
I am a bit confused between these.
Here is what I read about @Component
Put this “context:component” in the bean ...
16
votes
1
answer
21k
views
List of Spring Runtime Exceptions
Does anyone know where I can find a list of Spring's (3.0.x) runtime exceptions? I'm talking about exceptions like DataRetrievalFailureException; there's a whole set of these runtime exceptions that ...
16
votes
3
answers
12k
views
Upgrading to springframework.scheduling.concurrent?
As of Spring 3.0 the ScheduledTimerTask is deprecated and I can't understand how to upgrade to org.springframework.scheduling.concurrent.
<bean id="timerFactoryBean" class="org.springframework....
16
votes
7
answers
36k
views
Spring 3 Security: AccessDeniedHandler is not being invoked
I have a spring 3 application with the configurations given below. When any user tries to access a page and he/she isn't logged in, I get an Access is Denied exception with an ugly stack trace. How do ...
16
votes
5
answers
7k
views
Best practices when using Spring 3 annotations
I'm looking for some best practices when using Spring 3 annotations.
I'm currently moving to Spring 3 and from what I've read so far I see a lot of accent placed on using annotations and moving away ...
16
votes
3
answers
68k
views
RestTemplate post for entity
My post method gets called but my Profile is empty. What is wrong with this approach? Must I use @Requestbody to use the RestTemplate?
Profile profile = new Profile();
profile.setEmail(email); ...
16
votes
1
answer
15k
views
Resolve Spring @Value expression in JUnit tests
Here's a snippet of a Spring bean:
@Component
public class Bean {
@Value("${bean.timeout:60}")
private Integer timeout;
// ...
}
Now I want to test this bean with a JUnit test. I'm ...
16
votes
1
answer
44k
views
"The matching wildcard is strict, but no declaration can be found for element 'http'" Error
I am trying to configure NTLM authentication, but receive error:
cvc-complex-type.2.4.c: The matching wildcard is strict, but no
declaration can be found for element 'http'.
I read a lot of topics ...
15
votes
2
answers
42k
views
Spring: Attaching @Qualifer to Java-configured beans
In spring, you can XML-configure a bean to have a qualifier. I can't seem to find how I can attach a qualifier if configuring beans through Java annotations. What's up with that? Do I have to use just ...
15
votes
6
answers
27k
views
How to use property from property file specified in PropertyPlaceholderConfigurer in JSP
In my application context I have defined properties file:
<context:property-placeholder location="classpath:application.properties" />
I want to get value of the property defined in that file ...
15
votes
2
answers
49k
views
Spring MVC 3 : Ambiguous mapping found
I am playing with spring MVC 3.1 and testing different features. I wanted to verify following statement taken from @RequestMapping#value doc
If you have a single default method (without explicit path ...