Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7755465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:34:33+00:00 2026-06-01T12:34:33+00:00

I am building a spring based application that handles server-side game management for a

  • 0

I am building a spring based application that handles server-side game management for a mobile game app. The stack is Spring/Hibernate/Jersey. I want the clients (mobile) to call a REST API to update/retrieve the game state.

I created a TournamentController class which responsability is to update the tournament state using some business logic. This class is designed to be instanciated every time an operation on a Tournament is required and then thrown away.

public class TournamentController {

    @Autowired
    private TournamentDAO tournamentDAO;

    private final Tournament tournament;

    public TournamentController( Tournament tournament ) {
        this.tournament = tournament;
    }

    public void startTournament() {
        if ( tournament.getState() != TournamentState.SETUP ) {
            throw new TournamentAlreadyStartedException();
        }

        tournament.setState( TournamentState.IN_PROGRESS );

        //... some other logic and calls to other DAOs

        tournamentDAO.save( tournament );
    }

}

I also created a TournamentResource class that is the REST front end for the tournament. It’s responsability is to do some basic validation (user security, …) and exception translation.

@Path( "/tournament" )
@Component
@Scope( "prototype" )
public class TournamentResource {

    private static final Log log = LogFactory.getLog( TournamentResource.class );

    @Autowired
    private TournamentDAO tournamentDAO;

    @GET
    @Path( "{tournamentId}/start" )
    @Produces( MediaType.APPLICATION_JSON )
    @Transactional
    public TournamentDTO startTournament( @PathParam( "tournamentId" ) long tournamentId ) {
        Tournament tournament = tournamentDAO.getTournament( tournamentId, LockMode.PESSIMISTIC_WRITE );
        if ( tournament == null ) {
            throw new WebApplicationException( Status.NOT_FOUND );
        }

        try {
            TournamentController controller = new TournamentController( tournament );
            controller.startTournament();

        } catch ( TournamentAlreadyStartedException e ) {
            log.warn( "Could not start tournament " + tournamentId + " since it is already started." );
            throw new RestException( Status.BAD_REQUEST, "Tournament already started" );
        }

        return DTOConverterUtil.getTournament( tournament );
    }

}

I am using load time weaving with AspectJ. Here is my context:

   <context:annotation-config />

   <!-- Make spring aware ANY pojo with the @Configurable annotation -->
   <context:spring-configured />

   <!-- Scan all classes in com.mdarveau for annotations -->
   <context:component-scan base-package="so.question" />

   <!-- Load Time Weaver -->
   <context:load-time-weaver weaver-class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" aspectj-weaving="on" />

   <!-- DB config -->
   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
      ...
   </bean>

   <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
      <property name="dataSource" ref="dataSource" />
      <property name="packagesToScan" value="com.mdarveau.fnp.model" />
      <property name="hibernateProperties">
         <value>
            hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
         </value>
      </property>
   </bean>

   <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      <property name="sessionFactory" ref="sessionFactory" />
   </bean>

   <!-- enable @Transactional -->
   <tx:annotation-driven transaction-manager="txManager" mode="aspectj" />

My TournamentResource class is a singleton by design and is working well.

My problem is that when it instanciate the TournamentController using new instead of spring, it’s @Autowired attributes does not seems to be wired correctly. I tried to add the @Component annotation on it without success.

Should I make TournamentResource ApplicationContextAware and create the TournamentController through spring?

This must be a fairly common problem. I see a lot of examples where the backend is a singleton but I would like to avoid passing the Tournament to every method call on TournamentController (all then to all private methods in TournamentController).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:34:34+00:00Added an answer on June 1, 2026 at 12:34 pm

    Since you already have load-time weaving and <context:spring-configured />, you can declare your TournamentController as @Configurable.

    It will enable autowiring for instances of TournamentController created with new.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a web application with Spring Security that will live on Amazon
I'm building an application based on Spring 3 and i'm wondering, is there any
Hello I'm building spring-hibernate application. Do i realy need configuration from below ? <property
Are there solid guidelines available on 'architecting' and building spring based applications?Something that goes
I am building an indexer application based on a suffix tree, that enables me
(SOLVED) I'm building an application that can create some of its control dynamically, based
I'm building a Spring MVC web application with Tiles/JSP as the view technology. Previously
I'm building a Spring 3, JSF 2, OSGi (Virgo Tomcat 3.5.0.M03) application. Currently I
I am learning Spring and building a sample app. I am getting the error:
I am currently building an application using Tomcat, Spring and JAVA. I am using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.