Spring autowired bean is null NULL - spring

Why my beans is null?
[b]servlet-context.xml [/b]
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"
>
<!-- <context:annotation-config/>-->
<context:component-scan base-package="by"/>
<context:property-placeholder location="classpath:database.properties"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/javakava"/>
<property name="username" value="root"/>
<property name="password" value="admin"/>
</bean>
</beans>
[b]controller[/b]
public class Controller extends HttpServlet {
private static final long serialVersionUID = 1L;
#Autowired
private CommandFactory commandFactory;
#Override
public void init(ServletConfig servletConfig) throws ServletException {
super.init(servletConfig);
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
performAction(request, response);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
performAction(request, response);
}
private void performAction(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String page = null;
String paramPage = request.getParameter(Constants.PARAM_PAGE);
try {
if (paramPage != null && !paramPage.isEmpty()) {
Command command = commandFactory.getCommand(paramPage);
page = command.execute(request);
// Commands c = Commands.valueOf(paramPage);
// Command command = c.getCommandClass().newInstance();
page = command.execute(request);
RequestDispatcher requestDispatcher = request
.getRequestDispatcher(page);
requestDispatcher.forward(request, response);
} else {
throw new IllegalAccessError(
"Error with access to class from Controller.java");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
LoginCommand - Here is autowared TestService bean. In IDEA it's look's good. But in debug mode my testService is null..
#Component
public class LoginCommand implements Command {
#Autowired
TestService testService;
public String execute(HttpServletRequest request) {
DaoCheckUserImpl id = new DaoCheckUserImpl();
String pass = request.getParameter(Constants.PASS);
String login = request.getParameter(Constants.LOGIN);
id.checkUser();
String userN = id.getUserN();
String userP = id.getUserP();
String userRole = id.getUserRole();
int userId = id.getUserId();
if (userN.equals(login) & userP.equals(pass) & userRole.equals("admin")) {
/*
*
* Here testService is null[/b]
*
*/
List<Test> tests = testService.getAllTests();
request.setAttribute(Constants.TESTS, tests);
User user = new User();
user.setLogin(login);
request.getSession().setAttribute(Constants.USER, user);
return Constants.MAIN_ADMIN_PAGE;
} else {
}
return Constants.ERROR_LOGIN_PAGE;
}
}
}
TestService
#Service
public class TestService {
#Autowired
public DaoTestImpl daoTestImpl;
public List<Test> getAllTests() {
return daoTestImpl.getAllTests();
}
public Test selectTest(String idTest) {
return daoTestImpl.selectTest(idTest);
}
public void deleteTest(Test test) {
daoTestImpl.deleteTest(test);
}
[b]DaoTestImpl [/b]
Here I using JdbcDaoSupport , datasource injected with constructor.
#Component
public class DaoTestImpl extends JdbcDaoSupport implements DaoTest {
#Autowired
public DaoTestImpl(DataSource dataSource) {
setDataSource(dataSource);
}
...
public List<Test> getAllTests() throws DAOException {
return getJdbcTemplate().query(("SELECT *FROM tests"), rowMapper);
}
CommandFactory
#Component
public class CommandFactory {
#Autowired
public LoginCommand loginCommand;
public Command getCommand(String paramPage) {
Commands command = Commands.valueOf(paramPage.toUpperCase());
switch (command) {
case LOGIN_COMMAND:
return loginCommand;
commands
public enum Commands { LOGIN_COMMAND
/*login_Command(LoginCommand.class),

How do you create LoginCommand object?
Autowired is used by Spring to inject the correct bean. So it works only if LoginCommand is created by Spring. If you performed a NEW, or if you use another framework without a proper integration with Spring, this can explain your issue (for example Jersey 2 without the proper configuration).
EDIT:
By the way, you can had "#Required" annotation. This will not fix your problem, but the new error message can help you to understqnd what happen (in particular it will help to see if LoginCommand object is really created by Spring and if the autowired failed [as I think] because the instance of TestService was NOT found [package naming issue, classloader issue, etc.])
Did you check if all your components are in the "by" package (that is specified in component-scan)?

Related

configured as a single instance, but instantiated twice

spring.version=5.2.7.RELEASE
public class Service15 {
public Service15(){
System.out.println("service15 init");
}
}
public class Service15Factory implements FactoryBean, BeanFactoryAware {
private BeanFactory beanFactory;
public Service15Factory(){
System.out.println("serviceFactory15 init");
}
#Override
public Object getObject() throws Exception {
beanFactory.getBean("service16");
return new Service15();
}
#Override
public Class<?> getObjectType() {
return Service15.class;
}
#Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;
}
}
public class Service16 {
private Service15 service15;
public Service16(){
System.out.println("service16 init");
}
public void setService15(Service15 service15){
this.service15 = service15;
}
}
configuration:
<bean id="service15" class="com.myspring.service.Service15Factory" scope="singleton">
</bean>
<bean id="service16" class="com.myspring.service.Service16">
<property name="service15" ref="service15"></property>
</bean>
I created three classes,service15 will be created by getObject of Service15Factory, and Service16 dependent on service15,service15 will be Initialized twice

Spring Aop ProxyFactoryBean and ProxyFactory and ClassCastException

When i use ProxyFactoryBean to get proxy object, I get a ClassCastException,but when i use ProxyFactory's getProxy() to get a proxy object, it works properly. I use Spring 4.x.
Definition of Two Beans,WaiterTest and Seller:
public class WaiterTest {
public void greetTo(String name){
System.out.println("waiter greet to " + name +"...");
}
public void serveTo(String name){
System.out.println("waiter serving " + name + "...");
}
}
public class Seller {
public void greetTo(String name){
System.out.println("seller greet to " +name + "...");
}
}
Definition of Advice:
public class GreetingBeforeAdvice implements MethodBeforeAdvice{
public void before(Method method, Object[] args, Object obj) throws Throwable{
System.out.println(obj.getClass().getName() + "." + method.getName());
String clientName =(String) args[0];
System.out.println("How are you! Mr." + clientName +".");
}
}
Definition of Advisor:
public class GreetingAdvisor extends StaticMethodMatcherPointcutAdvisor {
public boolean matches(Method method, Class clazz) {
return "greetTo".equals(method.getName());
}
public ClassFilter getClassFilter() {
return new ClassFilter() {
public boolean matches(Class clazz) {
return WaiterTest.class.isAssignableFrom(clazz);
}
};
}
}
Test Class:
public class TestGreetingBeforeAdvisor {
public static void main(String[] args) {
//method one: use by ProxyFactory
WaiterTest targetWaiterTest = new WaiterTest();
Seller targetSeller = new Seller();
GreetingBeforeAdvice advice = new GreetingBeforeAdvice();
GreetingAdvisor advisor = new GreetingAdvisor();
advisor.setAdvice(advice);
ProxyFactory pf = new ProxyFactory();
pf.setTarget(targetWaiterTest);
pf.addAdvisor(advisor);
pf.setOptimize(true);
WaiterTest proxy = (WaiterTest) pf.getProxy();
proxy.greetTo("John");
proxy.serveTo("Tom");
ProxyFactory pf1 = new ProxyFactory();
pf1.setTarget(targetSeller);
pf1.addAdvisor(advisor);
Seller seller = (Seller) pf1.getProxy();
seller.greetTo("John");
System.out.println("=============");
//method two:Spring xml,use ProxyFactoryBean
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
WaiterTest test = (WaiterTest) ctx.getBean("waiterTest");
test .greetTo("John");
test .serveTo("John");
}
}
Beans.xml:
<bean id="waiterTarget" class="com.xxx.springaop.advisor.WaiterTest"/>
<bean id="sellerTarget" class="com.xxx.springaop.advisor.Seller"/>
<bean id="greetingAdvice1" class="com.xxx.springaop.advisor.GreetingBeforeAdvice"/>
<bean id="greetingAdvisor" class="com.xxx.springaop.advisor.GreetingAdvisor"
p:advice-ref="greetingAdvice1"/>
<bean id="parent" abstract="true" class="org.springframework.aop.framework.ProxyFactoryBean"
p:interceptorNames="greetingAdvisor"
p:proxyTargetClass="true"/>
<bean id="waiterTest" parent="parent" p:target-ref="waiterTarget"/>
<bean id="seller" parent="parent" p:target-ref="sellerTarget"/>
result:
com.xxx.springaop.advisor.WaiterTest.greetTo
How are you! Mr.John.
waiter greet to John...
waiter serving Tom...
seller greet to John...
=============
Exception in thread "main" java.lang.ClassCastException: com.sun.proxy.$Proxy12 cannot be cast to com.xxx.springaop.advisor.WaiterTest
at com.xxx.springaop.advisor.TestGreetingBeforeAdvisor.main(TestGreetingBeforeAdvisor.java:48)
Summarize:
WaiterTest proxy = (WaiterTest) pf.getProxy(); //success
WaiterTest test = (WaiterTest) ctx.getBean("waiterTest");//fail,ClassCastException
Why?
I was not able to reproduce your problem, but I did some refactoring on your code, and this works just fine for me. Maybe it helps you as well at least as a starting point..
Waiter.java
public class Waiter {
public void greetTo(String name) {
System.out.println("waiter greet to " + name + "...");
}
public void serveTo(String name) {
System.out.println("waiter serving " + name + "...");
}
}
GreetingBeforeAdvice.java
import org.springframework.aop.MethodBeforeAdvice;
import java.lang.reflect.Method;
public class GreetingBeforeAdvice implements MethodBeforeAdvice {
#Override
public void before(Method method, Object[] args, Object obj) throws Throwable {
String clientName = (String) args[0];
System.out.println("How are you! Mr." + clientName + ".");
}
}
GreetingAdvisor.java
import org.springframework.aop.ClassFilter;
import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;
import java.lang.reflect.Method;
public class GreetingAdvisor extends StaticMethodMatcherPointcutAdvisor {
public boolean matches(Method method, Class clazz) {
return "greetTo".equals(method.getName());
}
public ClassFilter getClassFilter() {
return new ClassFilter() {
public boolean matches(Class clazz) {
return Waiter.class.isAssignableFrom(clazz);
}
};
}
}
beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="waiter" class="Waiter"/>
<!-- Advisor Configuration -->
<bean id="greetingAdvice" class="GreetingBeforeAdvice"/>
<bean id="greetingAdvisor" class="GreetingAdvisor">
<property name="advice" ref="greetingAdvice"/>
</bean>
<bean id="waiterProxyFactory" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="interceptorNames">
<list>
<value>greetingAdvisor</value>
</list>
</property>
<property name="target" ref="waiter"/>
</bean>
</beans>
and finally App.java
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class App {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
final Waiter waiter = (Waiter) ctx.getBean("waiterProxyFactory");
waiter.greetTo("Koray Tugay");
waiter.serveTo("Koray Tugay");
}
}
The output for me is as follows using Spring 4.3.12:
How are you! Mr.Koray Tugay.
waiter greet to Koray Tugay...
waiter serving Koray Tugay...
I would say you have not configured 'target' object in you ProxyFactoryBean definition. A proxy cannot be created if it does not have a target.

How to inject bean in a Tapestry service

I want to inject bean in a Tapestry service (not in a page).
For the moment, I use this :
public class EntityRealm extends AuthorizingRealm {
ApplicationContext ctx = new ClassPathXmlApplicationContext("/application-context-security.xml");
SecurityServices securityServices = (SecurityServices)ctx.getBean("securityServices");
It works, but I want use this :
public class EntityRealm extends AuthorizingRealm {
#Inject
private SecurityServices securityServices;
And my applicationContext is in the web.xml.
In this second case, the injection doesn't work. Why ?
AppModule.java :
public class AppModule
{
//#Resource(name = "realm")
#Inject
private static EntityRealm realm;
#Contribute(WebSecurityManager.class)
public static void addRealms(Configuration<EntityRealm> configuration) {
//EntityRealm realm = new EntityRealm();
configuration.add(realm);
}
public static void contributeFactoryDefaults( MappedConfiguration<String, Object> configuration)
{
configuration.override(SecuritySymbols.LOGIN_URL, "/login");
configuration.override(SecuritySymbols.UNAUTHORIZED_URL, "/login");
configuration.override(SecuritySymbols.SUCCESS_URL, "/index");
configuration.override(SymbolConstants.APPLICATION_VERSION, "2.0-SNAPSHOT");
}
public static void contributeApplicationDefaults(MappedConfiguration<String, Object> configuration)
{
configuration.add(SymbolConstants.HMAC_PASSPHRASE, new BigInteger(130, new SecureRandom()).toString(32));
configuration.add(SymbolConstants.SUPPORTED_LOCALES, "en,fr");
configuration.add( "tapestry.default-cookie-max-age", "31536000" );
}
public RequestFilter buildTimingFilter(final Logger log)
{
return new RequestFilter()
{
public boolean service(Request request, Response response, RequestHandler handler)
throws IOException
{
long startTime = System.currentTimeMillis();
try
{
return handler.service(request, response);
} finally
{
long elapsed = System.currentTimeMillis() - startTime;
log.info(String.format("Request time: %d ms", elapsed));
}
}
};
}
public void contributeRequestHandler(OrderedConfiguration<RequestFilter> configuration,
#Local
RequestFilter filter)
{
configuration.add("Timing", filter);
}
}
And the EntityRealm.java :
public class EntityRealm extends AuthorizingRealm {
//***************************************
//************* Attributes *************
//***************************************
//ApplicationContext ctx = new ClassPathXmlApplicationContext("/application-context-security.xml");
//SecurityServices securityServices = (SecurityServices)ctx.getBean("securityServices");
//#Resource(name = "securityServices")
#Inject
private SecurityServices securityServices;
//***************************************
//************ Constructors *************
//***************************************
public EntityRealm() {
super(new MemoryConstrainedCacheManager());
setName("myapprealm");
setAuthenticationTokenClass(UsernamePasswordToken.class);
}
//***************************************
//********** Public Methods *************
//***************************************
#Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
if (principals == null) throw new AuthorizationException("PrincipalCollection was null, which should not happen");
application-context.xml :
<bean id="realm" class="net.atos.m2m.telecom.ihm.services.EntityRealm">
<property name="securityServices" ref="securityServices"></property>
</bean>
<bean id="securityServices" class="net.atos.m2m.telecom.ihm.applicatif.services.security.impl.SecurityServicesImpl">
<property name="servicesTelSecu" ref="servicesTelSecu"></property>
<property name="converterSecDSPtoDTO" ref="converterSecDSPtoDTO"></property>
<property name="converterSecDTOtoDSP" ref="converterSecDTOtoDSP"></property>
</bean>
Can you help me ?
Thank you.
How i say in previous comment, if you create EntityRealm in this way .. new EntityRealm() the inject\autowire does not work.
You must define EntityRealm as bean .. XML or Annotation.
<bean id="entityRealm" class="package.EntityRealm"/>
<bean id="securityServices" class="package.SecurityServices"/>
You can use #Resource instead,
#Resource(name = "securityServices")
private SecurityServices securityServices;
And make sure that application-context-security.xml file is loaded by Spring.

spring 2.5.6 DI issue in jsf application

i get NPE(null pointer exception) each time when i try to insert data into database. help me to resolve this issue. i have import all the necessary libraries which are requried for spring.
this is my applicationContext.xml file where i have configure all the beans.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="personService" class="com.ecommerce.assignment.service.PersonService">
<property name="personDAO" ref="personDAO" />
</bean>
<bean id="personBean" class="com.ecommerce.assignment.bean.PersonBean" />
<bean id="personDAO" class="com.ecommerce.assignment.dao.PersonDAO" />
</beans>
this is interface of person DAO.
public interface IPersonDAO {
public void addPerson(Person instance);
}
this personDAO class implementing IpersonDAO interface and its unimplemented methods.
public class PersonDAO implements IPersonDAO {
#Override
public void addPerson(Person instance) {
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction().begin();
session.saveOrUpdate(instance);
session.getTransaction().commit();
session.close();
}
}
this is interface personService.
public interface IPersonService {
public void addPerson(Person instance);
}
public class PersonService implements IPersonService,Serializable {
private IPersonDAO personDAO;
public IPersonDAO getPersonDAO() {
return personDAO;
}
public void setPersonDAO(IPersonDAO personDAO) {
this.personDAO = personDAO;
}
#Override
public void addPerson(Person instance) {
getPersonDAO().addPerson(instance);
}
}
public class PersonBean implements Serializable {
private static final long serialVersionUID = 1L;
private String emailAddress;
private String password;
private String username;
#ManagedProperty(value = "#{personService}")
private IPersonService iPersonService;
public void addPerson(){
try{
Person person = new Person();
person.setUsername(getUsername());
person.setEmailAddress(getEmailAddress());
person.setPassword(getPassword());
iPersonService.addPerson(person);
}
catch(Exception ex){
ex.printStackTrace();
}
}
}
As your person bean is managed by Spring, you should use #Autowired annotation to make dependency injection, or inject it via XML, as you did for PersonService. You can as well declare the bean as #Component and #Scope.
You error is in injecting service in a bean by using JSF's #ManagedProperty annotation that works solely within JSF context, that is, with JSF managed beans, annotated with #ManagedBean, or declared via XML.

How to test the destruction of session scoped beans in jUnit?

I have a session scoped bean in which I hold some user data and want to write a unit test to ensure that it remains session scoped.
I want to mock the starting and the ending of a session in jUnit and compare the values of the session scoped bean.
For now I have the following (rough drafts) of the unit test:
I use a custom context loader to register the session scope.
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.test.context.support.GenericXmlContextLoader;
import org.springframework.web.context.request.SessionScope;
public class SessionScopedGenericXmlContextLoader extends GenericXmlContextLoader {
#Override
protected void customizeBeanFactory(final DefaultListableBeanFactory beanFactory) {
beanFactory.registerScope("session", new SessionScope());
super.customizeBeanFactory(beanFactory);
}
}
The unit test:
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(loader = SessionScopedGenericXmlContextLoader.class,
locations = { "classpath:/test-applicationContext.xml","classpath:/cache-config.xml" })
public class CachingTest extends AbstractJUnit4SpringContextTests {
// Session scoping
protected MockHttpSession session;
protected MockHttpServletRequest request;
ApplicationContext ctx;
CacheManager cacheManager;
Cache accountSettingsCache;
#Autowired
#Qualifier("cachedMethods")
DummyCacheMethods methods;
#Autowired
private SecurityContextHolder contextHolder;
protected void startRequest() {
request = new MockHttpServletRequest();
request.setSession(session);
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
}
protected void endRequest() {
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).requestCompleted();
RequestContextHolder.resetRequestAttributes();
request = null;
}
protected void startSession() {
session = new MockHttpSession();
}
protected void endSession() {
session.clearAttributes();
session = null;
}
#Before
public void constructSession() {
ctx = applicationContext;
cacheManager = (CacheManager) ctx.getBean("cacheManager");
accountSettingsCache = cacheManager.getCache("accountSettingsCache");
startRequest();
startSession();
}
#After
public void sessionClean() {
endRequest();
endSession();
contextHolder.clearContext();
}
#Test
// #DirtiesContext
public void checkSession1() {
final Authentication authentication = new Authentication() {
public String getName() {
return "Johny";
}
public void setAuthenticated(final boolean isAuthenticated) throws IllegalArgumentException {
}
public boolean isAuthenticated() {
return true;
}
public Object getPrincipal() {
final CustomUserDetails pr = new CustomUserDetails();
pr.setUsername("Johny");
return pr;
}
public Object getDetails() {
return null;
}
public Object getCredentials() {
return null;
}
public Collection<GrantedAuthority> getAuthorities() {
return null;
}
};
contextHolder.getContext().setAuthentication(authentication);
assertTrue(methods.getCurrentUserName().equals(accountSettingsCache.get("currentUser").get()));
assertTrue(methods.getCurrentUserName().equals(((CustomUserDetails) authentication.getPrincipal()).getUsername()));
}
#Test
// #DirtiesContext
public void testSession2() {
final Authentication authentication2 = new Authentication() {
public String getName() {
return "James";
}
public void setAuthenticated(final boolean isAuthenticated) throws IllegalArgumentException {
}
public boolean isAuthenticated() {
return true;
}
public Object getPrincipal() {
final CustomUserDetails pr = new CustomUserDetails();
pr.setUsername("James");
return pr;
}
public Object getDetails() {
return null;
}
public Object getCredentials() {
return null;
}
public Collection<GrantedAuthority> getAuthorities() {
return null;
}
};
SecurityContextHolder.setContext(contextHolder.getContext());
SecurityContextHolder.clearContext();
SecurityContextHolder.getContext().setAuthentication(authentication2);
assertTrue(methods.getCurrentUserName().equals(accountSettingsCache.get("currentUser").get()));
assertTrue(methods.getCurrentUserName().equals(((CustomUserDetails) authentication2.getPrincipal()).getUsername()));
}
#Test
public void testWiring() {
assertTrue("cacheManager is null", cacheManager != null);
assertTrue("accountSettingsCache is null", accountSettingsCache != null);
}
}
And the relevant function from DummyCachedMethods is:
#Cacheable(value = { "accountSettingsCache" }, key = "new String(\"currentUser\")")
public String getCurrentUserName() {
return WebUtils.getCurrentUser().getUsername();
}
WebUtils.getCurrentUser() just returns the current Principal from the SecurityContext.
But this does not work, the test does not pass at this line:
assertTrue(methods.getCurrentUserName().equals(((CustomUserDetails) authentication2.getPrincipal()).getUsername()));
Since the method call is cached, it still returns Johnny instead of James.
My cache related beans are:
<bean id="accountSettingsCache" class="org.springframework.cache.concurrent.ConcurrentMapCache" scope="session">
<constructor-arg>
<value>accountSettingsCache</value>
</constructor-arg>
<aop:scoped-proxy proxy-target-class="false" />
</bean>
<bean id="defaultCache" class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="defaultCache" />
<bean id="cacheManager" class="my.package.DynamicCacheManager" scope="session">
<property name="caches">
<set>
<ref bean="accountSettingsCache" />
<ref bean="defaultCache" />
</set>
</property>
<aop:scoped-proxy />
</bean>
accountSettingsCache is session scoped, I want to start a new session and destroy it.
It does pass if I uncomment the DirtiesContext annotations, but I guess it's not what I want.
What am I missing ?

Resources