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 8366469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:55:38+00:00 2026-06-09T12:55:38+00:00

I’m trying to follow the guide at this website to properly scope my beans

  • 0

I’m trying to follow the guide at this website to properly scope my beans for a Spring web app:

http://richardchesterwood.blogspot.com/2011/03/using-sessions-in-spring-mvc-including.html

I’m trying to follow method 3, which basically means I want to scope my component classes as session, and therefore I have to scope my controller classes at request. I have the controller put into my JSP page so it can be used.

When I try to do this, though, my webapp has build issues, and when I try to go to the web page it gives me a 503 service_unavailable error.

The build error is:

SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name
‘org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0’:
Initialization of bean failed; nested exception is
java.lang.IllegalStateException: Cannot map handler
‘currentWeekController’ to URL path [/TimeTracking]: There is already
handler ‘scopedTarget.currentWeekController’ mapped.

Here are the relevant classes and the jsp page. If you need anything else please just ask!

CurrentWeekController Controller class:

package controllers;

import javax.servlet.http.HttpServletRequest;

import models.CurrentWeek;
import models.ModelMap;
import models.User;

import org.joda.time.MutableDateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * this is the controller for current week, it lets you change the current week
 * and get values from the current week
 * 
 * @author CorayThan
 * 
 */
@Controller
@Scope("Request")
public class CurrentWeekController {

    private static final int MONDAY = 1;
    private static final int TUESDAY = 2;
    private static final int WEDNESDAY = 3;
    private static final int THURSDAY = 4;
    private static final int FRIDAY = 5;
    private static final int SATURDAY = 6;
    private static final int SUNDAY = 7;

    @Autowired
    private User user;

    @Autowired
    private CurrentWeek currentWeek;

    @Autowired
    private ModelMap hashmap;

    /**
     * @return the user
     */
    public User getUser() {
        return user;
    }

    /**
     * @param user
     *            the user to set
     */
    public void setUser(User user) {
        this.user = user;
    }

    /**
     * @return the currentWeek checks to make sure the week isn't null and its
     *         monday isn't null and fixes them if they are
     */
    public CurrentWeek getCurrentWeek() {
        if (currentWeek == null) {
            this.createNewCurrentWeek();
        }
        if (currentWeek.getMonday() == null) {
            this.createCurrentWeek(MutableDateTime.now());
        }
        return currentWeek;
    }

    /**
     * @param currentWeek
     *            the currentWeek to set
     */
    public void setCurrentWeek(CurrentWeek currentWeek) {
        this.currentWeek = currentWeek;
    }

    /**
     * @return the hashmap
     */
    public ModelMap getHashmap() {
        return hashmap;
    }

    /**
     * @param hashmap
     *            the hashmap to set
     */
    public void setHashmap(ModelMap hashmap) {
        this.hashmap = hashmap;
    }

    /**
     * no arg constructor
     */
    public CurrentWeekController() {

    }

    /**
     * this is a post method called when a button is clicked on the time
     * tracking jsp page. It reloads the page with a different week
     * 
     * @param pageWeek
     * @param request
     * @return
     */

    @RequestMapping(value = "TimeTracking")
    public ModelAndView changeTheWeek(HttpServletRequest request) {
        String whichWayWeek = request.getParameter("changeWeek");

        if ("Previous Week".equals(whichWayWeek)) {
            this.subtractOneWeek();
        }
        if ("Next Week".equals(whichWayWeek)) {
            this.addOneWeek();
        }

        return new ModelAndView("redirect:/jsp-pages/TimeTracking.jsp",
                hashmap.makeHashMap());
    }

    /**
     * This creates a current week object by setting that week's monday to the
     * proper monday for that week using whatever date you give it
     * 
     * 
     * @param calendar
     * @return
     */
    public CurrentWeek createCurrentWeek(MutableDateTime theCurrentDate) {

        int day = checkForNull(theCurrentDate);

        switch (day) {

        case SUNDAY:
            theCurrentDate.addDays(-6);
            currentWeek.setMonday(theCurrentDate);
            break;
        case SATURDAY:
            theCurrentDate.addDays(-5);
            currentWeek.setMonday(theCurrentDate);
            break;
        case FRIDAY:
            theCurrentDate.addDays(-4);
            currentWeek.setMonday(theCurrentDate);
            break;
        case THURSDAY:
            theCurrentDate.addDays(-3);
            currentWeek.setMonday(theCurrentDate);
            break;
        case WEDNESDAY:
            theCurrentDate.addDays(-2);
            currentWeek.setMonday(theCurrentDate);
            break;
        case TUESDAY:
            theCurrentDate.addDays(-1);
            currentWeek.setMonday(theCurrentDate);
            break;
        case MONDAY:

            currentWeek.setMonday(theCurrentDate);
            break;
        default:
            this.setCurrentWeek(null);
            break;

        }
        return this.getCurrentWeek();

    }

    /**
     * @param theCurrentDate
     * @return
     * makes sure the current date isn't null, and returns an int equal to 
     * the day of the week it is in joda time
     */
    private int checkForNull(MutableDateTime theCurrentDate) {
        int day = 0;
        if (theCurrentDate != null) {
            day = theCurrentDate.getDayOfWeek();
        }
        return day;
    }

    /**
     * makes a new current week set to the real current week
     * 
     * @return
     */

    public CurrentWeek createNewCurrentWeek() {
        MutableDateTime dateTime = MutableDateTime.now();
        CurrentWeek currentWeek = new CurrentWeek();
        this.setCurrentWeek(currentWeek);

        return createCurrentWeek(dateTime);
    }

    /**
     * subtracts one week from a currentweek
     * 
     * 
     * @return
     */
    public void subtractOneWeek() {

        MutableDateTime newMonday = (MutableDateTime) this.getCurrentWeek()
                .getMonday().clone();
        newMonday.addDays(-7);

        this.setCurrentWeek(createCurrentWeek(newMonday));

    }

    /**
     * adds one week to a currentweek
     * 
     * @param currentWeek
     * @return
     */
    public void addOneWeek() {

        MutableDateTime newMonday = (MutableDateTime) this.getCurrentWeek()
                .getMonday().clone();
        newMonday.addDays(7);

        this.setCurrentWeek(createCurrentWeek(newMonday));
    }

    /**
     * TODO: make this method into a method that accepts a current week and
     * checks if you can add a week to it without going entirely into the future
     * 
     * @param currentWeek
     * @return
     */
    public CurrentWeek checkIfCurrentWeekIsEntirelyInFuture() {
        return this.getCurrentWeek();

    }

    /**
     * returns the first day of the week as a formatted date time
     * 
     * @return
     */

    public String firstDayOfThisWeek() {

        MutableDateTime firstDay = this.getCurrentWeek().getSunday();

        DateTimeFormatter dateFormatter = DateTimeFormat
                .forPattern("MM/dd/yyyy");

        return dateFormatter.print(firstDay);
    }

    /**
     * returns the last day of this week as a formatted date time
     * 
     * @return
     */

    public String lastDayOfThisWeek() {

        MutableDateTime lastDay = this.getCurrentWeek().getSaturday();

        DateTimeFormatter dateFormatter = DateTimeFormat
                .forPattern("MM/dd/yyyy");

        return dateFormatter.print(lastDay);
    }

}

And here is the CurrentWeek component class.

package models;

import org.joda.time.MutableDateTime;
import org.springframework.stereotype.Component;

/**
 * this is a class that holds the current week for views
 * 
 * @author CorayThan
 * 
 */
@Component
// @Scope ("Session")
public class CurrentWeek {

    private MutableDateTime monday;

    /**
     * default constructor
     */
    public CurrentWeek() {

    }

    /**
     * @return a MutableDateTime which is of the correct date for this specific
     *         day
     */
    public MutableDateTime getSunday() {
        MutableDateTime sunday = (MutableDateTime) monday.clone();
        sunday.addDays(-1);
        return sunday;
    }

    /**
     * @return a MutableDateTime which is of the correct date for this specific
     *         day
     */
    public MutableDateTime getMonday() {
        return monday;
    }

    /**
     * @param saturdayTime
     *            pass a MutableDateTime to set this date of the CurrentWeek
     *            object to the correct date for that week
     */
    public void setMonday(MutableDateTime saturdayTime) {
        this.monday = saturdayTime;
    }

    /**
     * @return a MutableDateTime which is of the correct date for this specific
     *         day
     */
    public MutableDateTime getTuesday() {
        MutableDateTime tuesday = (MutableDateTime) monday.clone();
        tuesday.addDays(1);
        return tuesday;
    }

    /**
     * @return a MutableDateTime which is of the correct date for this specific
     *         day
     */
    public MutableDateTime getWednesday() {
        MutableDateTime wednesday = (MutableDateTime) monday.clone();
        wednesday.addDays(2);
        return wednesday;
    }

    /**
     * @return a MutableDateTime which is of the correct date for this specific
     *         day
     */
    public MutableDateTime getThursday() {
        MutableDateTime thursday = (MutableDateTime) monday.clone();
        thursday.addDays(3);
        return thursday;
    }

    /**
     * @return a MutableDateTime which is of the correct date for this specific
     *         day
     */
    public MutableDateTime getFriday() {
        MutableDateTime friday = (MutableDateTime) monday.clone();
        friday.addDays(4);
        return friday;
    }

    /**
     * @return a MutableDateTime which is of the correct date for this specific
     *         day
     */
    public MutableDateTime getSaturday() {
        MutableDateTime saturday = (MutableDateTime) monday.clone();
        saturday.addDays(5);
        return saturday;
    }

}

And finally the jsp file that references the CurrentWeekController:

<%@page contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="daos.*"%>
<%@page import="controllers.*"%>
<%@page import="models.*"%>

<jsp:useBean id="userDao" class="daos.UserDao" scope="request" />

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="timeTrackingControl"
    class="controllers.TimeTrackingController" scope="request" />
<jsp:useBean id="currentWeek" class="controllers.CurrentWeekController"
    scope="request" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Time Tracking Page</title>
<script type="text/javascript" src= "../javascriptpages/timeTracking.js"></script>
<link rel="stylesheet" type="text/css" href="csspages/global.css" />

<style type="text/css"></style>
</head>

<body>

    <div>
        <h1>User Time Tracking Page</h1>

    </div>
    <div id="content">

    <form method="POST" action="../TimeTracking.html">
            <span> <input name="changeWeek" type="submit" value="Previous Week"/> Hours for the week of
                <%=currentWeek.firstDayOfThisWeek()%> until <%=currentWeek.lastDayOfThisWeek()%>
                <input name="changeWeek" type="submit" value="Next Week"/>
            </span>
    </form>


            <table border="1">
                <tr>
                    <th>Sunday</th>
                    <th>Monday</th>
                    <th>Tuesday</th>
                    <th>Wednesday</th>
                    <th>Thursday</th>
                    <th>Friday</th>
                    <th>Saturday</th>
                </tr>
                <tr>
                    <td><%=timeTrackingControl.totalWorkTimeForOneDate(currentWeek.getCurrentWeek().getSunday())%></td>
                    <td><%=timeTrackingControl.totalWorkTimeForOneDate(currentWeek.getCurrentWeek().getMonday())%></td>
                    <td><%=timeTrackingControl.totalWorkTimeForOneDate(currentWeek.getCurrentWeek().getTuesday())%></td>
                    <td><%=timeTrackingControl.totalWorkTimeForOneDate(currentWeek.getCurrentWeek().getWednesday())%></td>
                    <td><%=timeTrackingControl.totalWorkTimeForOneDate(currentWeek.getCurrentWeek().getThursday())%></td>
                    <td><%=timeTrackingControl.totalWorkTimeForOneDate(currentWeek.getCurrentWeek().getFriday())%></td>
                    <td><%=timeTrackingControl.totalWorkTimeForOneDate(currentWeek.getCurrentWeek().getSaturday())%></td>
                </tr>
            </table>

            <input type="button" value="<%=timeTrackingControl.displayClockButton()%>"
                onClick="clockInOrOutReloadPage()">

    </div>

</body>
</html>
  • 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-09T12:55:39+00:00Added an answer on June 9, 2026 at 12:55 pm

    Controllers should be application scoped in Spring MVC (you don’t need to explicitly scope them as that’s the default).

    Any request level data should be done using model attributes:

    @ModelAttribute("foo")
    public Foo createFoo(@RequestParam("bar") int bar) {
       return new Foo(bar);
    }
    
    
    @RequestMapping(...)
    public ModelAndView baz(HttpServletRequest req, HttpServletResponse response,
        @ModelAttribute("foo") Foo foo) {
       ...
    }
    

    Spring will automatically create the “Foo” instance (via your “createFoo”) method and put it in request scope. Then, by annotating a method parameter in your mapped method, it will automatically pull that from request scope and pass it along to your method.

    If you want a model attribute to be stored in session scope, you add this annotation to the controller class:

    @SessionAttributes({"foo"})
    

    This means you should not have any state in your controller itself, only in model attributes (whether at request or session scope), and should inject that state into your mapped method calls.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.