struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris <>
Subject Spring Injection Strange behaviour
Date Sat, 05 Sep 2015 12:47:26 GMT
I'm trying to use the Spring plugin to inject a dependency into my action at runtime. This
is the first time I've tried this with Struts2 so I may have missed something but I'm stumped
because I can see the dependency is injected but then the object is later null when I need
to use it. Here is my action class code:

public class UserRegisterAction extends ActionSupport {
    private User user = new User();

    public String execute(){
        return "success";

    public UserServiceImpl getUserService(){
        return userService;

    UserServiceImpl userService;
    public void setUserService(UserServiceImpl us){
        this.userService = us;

Using the debugger I can see that upon startup "setUserService is called and this.userService
is set, so the injection appears to be working ok, but when the execute method is called when
the page is submitted userService is null. I'm quite new to Struts but I don't understand
how my userService is being null.

Can anyone see what I am missing?

My applicationContext:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns=""
       xmlns:xsi="" xmlns:tx=""

    <bean class=""

    <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect"
                <property name="database" value="MYSQL" />
                <property name="showSql" value="true" />

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="" />
        <property name="url" value="jdbc:mysql://" />
        <property name="username" value="xxxxxx" />
        <property name="password" value="xxxxxx" />

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />

    <tx:annotation-driven transaction-manager="transactionManager" />

    <bean id="userService" class="com.xxxxx.service.UserServiceImpl" scope="prototype"/>

    <bean id="userAction" class="com.xxxxxx.action.UserRegisterAction">
        <property name="userService" ref="userService"/>



<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns=""




To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message