spring

Injecting Mockito mocks into a Spring bean

I would like to inject a Mockito mock object into a Spring (3+) bean for the purposes of unit testing with JUnit. My bean dependencies are currently injected by using the @Autowired annotation on private member fields. I have considered using ReflectionTestUtils.setField but the bean instance that I wish to inject is actually a proxy an...

Spring, Hibernate, EntityManager and class inheritance

Hi, I'm pretty much new to Spring & Hibernate. In our team, we are building a web application using Struts 2 for the presentation layer, with Spring 3 and Hibernate 3 (with Annotations) underneath. We are still debating on whether to use DAOs or not and Session's or EntityManager's for CRUD operations. Setting aside the question of which...

Which view will be resolved, code from spring's docs

So when you go to /appointments the get() action is called, so then would the view be get.jsp (assuming you are using .jsp, and assuming you are mapping action names to views)? And what about the getnewform? It seems to be returning an object? Is that basically passed into the view? @Controller @RequestMapping("/appointments") public...

Autowire Annotation in Spring without using Component Scanning

Is it possible to autowire beans using the @Autowired annotation without using component scanning? ...

A typical lifecycle of a Hibernate object in a web app - ?

Describe please a typical lifecycle of a Hibernate object (that maps to a db table) in a web app. Suppose, you create a new instance of an object and persist in the db. But during the app lifetime you'll be working on a detached object and finally you need to update it in the database, for example on exit. How does it look like with hibe...

Using Interceptors in Spring for Business logic concerns

I am new to working with Spring on regular basis so I had a basic design question on it. Should the concept of interceptors be used for separating out business logic in an application. E.g. A method getData is called from 3 classes/ One of the 3 needs some more processing before reaching the data. This processing is not a concern like l...

How to make a legacy webapp spring aware at the container level for bean autowire into Servlets?

We have a legacy web application (not Spring based) and are looking for best practices to autowire some newer Spring configured (thread safe) service beans into instance variables in several of the legacy servlets. Rewriting every servlet to Spring MVC is out of scope. For testability, we do not want any Spring specific bean lookup cod...

Spring MVC jQuery remote validation

Hi, I am using Spring MVC on the server side, but in one of the pages I decided to create an AJAX validation with jQuery rather than the default Spring validation. Everything works great, except when I have to do a remote validation to check if a "title" already exists in the database. For the javascript I have the following: var valid...

Spring validation errors not displayed

I have the following situation. I have a validator to validate my command object and set the errors on a Errors object to be displayed in my form. The validator is invoked as expected and works okay, but the errors i set on the Errors objects are not displayed, when i am sent back to my form because of the validation errors. Validator:...

What's mean that Caused by: javax.validation.ValidationException: Unable to find a default provider ?

I compiling springframework project using with springframework-3.0.1. But, I got error messages, "Caused by: javax.validation.ValidationException: Unable to find a default provider", What is it? help me, ...

Dependency on Spring's annotations

I have annotated my classes with @Repository, @Resource, @Component, @Service annotations but these classes must run in 2 environments. The first environment is Spring 2.x based while the other has no spring at all. I'm sure the code will fail without the spring jars & I want to know ideas from you on how I can retain the annotations but...

Spring: Same object, different validation

Hello, I have an object called User where I save all the data of the User. I have some annotations to perform validation and it works fine. public class User{ @NotEmpty @Email @Size(max=100) @Column(name="username", length=100, nullable=false, unique=true) private String username; @NotEmpty @Size(min=5, max...

How to hold a queue of messages and have a group of working threads without polling?

I have a workflow that I want to looks something like this: / Worker 1 \ =Request Channel= -> [Holding Queue|||] -> Worker 2 -> =Response Channel= \ Worker 3 / That is: Requests come in and they enter a FIFO queue Identical workers then pick up tasks ...

Using ControllerClassNameHandlerMapping with @Controller and extending AbstractController

Hey there, actually I thought I was trying something really simple. ControllerClassNameHandlerMapping sounded great to produce a small spring webapp using a very lean configuration. Just annotate the Controller with @Controller, have it extend AbstractController and the configuration shouldn't need more than this <context:component-s...

How to create an aspect on class, that is not a bean using Spring AOP?

Hello, I work on an legacy application, where Spring AOP (namely ProxyFactoryBean) is used. I need to add an aspect around a method of a certain class. This class is not a bean however. The AspecjJ pointcut expression would be like this: execution(* xyz.package.Class.method()) I created a MethodInterceptor and AspectJExpressionPoin...

Problems overriding a property to null in Spring bean declaration

Just wondering if there is a way in Spring to have a parent controller: <bean id="parentController" class="org.springframework.web.portlet.mvc.SimpleFormController" abstract="true"> <property name="validator" ref="validatorImpl"/> ... </bean> , and a class extending it: <bean id="child1Controller" class="com.portlet.contr...

Spring: Using "Lookup method injection" for my ThreadFactory looks not scalable.

Hi, We're building a ThreadFactory so everytime a singleton controller needs a new thread, i get a new instance everytime. Looking at Lookup method injection looks good but what if we have multiple thread classes? I like the fact that i can autowire my threadBeans. like: public abstract class ThreadManager { public abstract T...

Trying to create spring project with maven

Hello everyone I was just going trough http://static.springsource.org/docs/Spring-MVC-step-by-step/part1.html spring tutorial, and I thought its old I'll think something better on my own. For starters how do I start spring project with maven, which archtype should I choose? I wanna create simple spring app, write class which I will deplo...

Spring MVC + Hibernate encoding problem

I work on Spring MVC + Hibernate application, use MySQL (ver. 5.0.51a) with the InnoDB engine. The problem appears when I am sending a form with cyrillic characters. As the result, database contains senseless chars in unknown encoding. All the JSP pages, database (+ tables and fields) created using UTF-8. Hibernate config also contains...

spring roo backup command lost my files

I generated spring roo project and modifies .jspx files to my styles. Unfortunately, when i used the backup command, spring roo was auto-generated files to the original one. Thus, my .jspx files are noy my styles. How should i do to recovery my files back from this command. ...