k6669999
02-22-2007, 03:24 PM
Hello,
I am new to spring and I am trying to run the example movie finder -- with a few changes that should not change the behavior. I have a program.cs that runs the console program. This program creates an ApplicationContext, calls the MovieLister and gets moviedirectedby. In the app.config I have set up the SimpleMovieFinder as the class that MovieLister calls.
I compile it in visual studio 2005. It compiles and starts. I creates the injection properly as far as I can tell because when it crashes I can check the value of the set method in MovieLister -- it says Spring.ExampleMovieFinder.SimpleMovieFinder. also in the output before crash it shows the list defined in SimpleMovieFinder.
Here is my program.cs, MovieLister.cs, IMovieFinder.cs, SimpleMovieFinder.cs and App.Config:
/////////////////////////////////////////////////////////////////////////////
Program.cs:
using System;
using System.Collections.Generic;
using System.Text;
using Spring.Context;
namespace Spring.ExampleMovieFinder {
class Program {
static void Main(string[] args) {
Console.WriteLine("[Program] Starting...");
Spring.Context.IApplicationContext ctx =
Spring.Context.Support.ContextRegistry.GetContext( );
Console.WriteLine("[Program] After creating ctx...");
MovieLister lister = (MovieLister)ctx.GetObject("MyMovieLister");
Console.WriteLine("[Program] After creating lister...");
String movie = lister.MoviesDirectedBy("Reservoir Dogs");
Console.WriteLine("\nSearching for movie...\n");
Console.WriteLine(movie);
Console.WriteLine("\nMovieApp Done.\n\n");
}
}
}
/////////////////////////////////////////////////////////////////////////////
MovieLister.cs:
using System;
using System.Collections.Generic;
using System.Text;
namespace Spring.ExampleMovieFinder
{
public class MovieLister
{
public MovieLister() { }
public IMovieFinder movieFinder {
set {
movieFinder = value;
}
get {
return movieFinder;
}
}
public String MoviesDirectedBy(String MovieName) {
String list = movieFinder.FindAll();
return list;
}
}
}
/////////////////////////////////////////////////////////////////////////////
IMovieFinder.cs:
using System;
using System.Collections.Generic;
using System.Text;
namespace Spring.ExampleMovieFinder
{
public interface IMovieFinder
{
String FindAll();
}
}
/////////////////////////////////////////////////////////////////////////////
SimpleMovieFinder.cs:
using System;
using System.Collections.Generic;
using System.Text;
namespace Spring.ExampleMovieFinder
{
class SimpleMovieFinder: IMovieFinder
{
private String list = "Desperado, From Dusk Till Dawn, Reservoir Dogs, Kill Bill 1, Kill Bill 2";
public SimpleMovieFinder()
{
Console.WriteLine("[SimpleMovieFinder] in constructor...");
Console.WriteLine("[SimpleMovieFinder] list: " + list);
}
public String FindAll()
{
Console.WriteLine("[SimpleMovieFinder] Find all...");
return list;
}
}
}
/////////////////////////////////////////////////////////////////////////////
App.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>
<spring>
<context>
<resource uri="config://spring/objects"/>
</context>
<objects xmlns="http://www.springframework.net">
<object name="MyMovieLister"
type="Spring.ExampleMovieFinder.MovieLister, Spring.ExampleMovieFinder">
<!-- using setter injection... -->
<property name="movieFinder" ref="MyMovieFinder"/>
</object>
<object name="MyMovieFinder"
type="Spring.ExampleMovieFinder.SimpleMovieFinder, Spring.ExampleMovieFinder">
</object>
<object name="AnotherMovieFinder"
type="Spring.ExampleMovieFinder.ColonDelimitedMovieFinde r, Spring.ExampleMovieFinder">
</object>
</objects>
</spring>
</configuration>
Here is the output:
[Program] Starting...
[SimpleMovieFinder] in constructor...
[SimpleMovieFinder] list: Desperado, From Dusk Till Dawn, Reservoir Dogs, Kill Bill 1, Kill Bill 2
Here is where it hangs for a second and comes back with StackOverFlowException.
I am new to spring and I am trying to run the example movie finder -- with a few changes that should not change the behavior. I have a program.cs that runs the console program. This program creates an ApplicationContext, calls the MovieLister and gets moviedirectedby. In the app.config I have set up the SimpleMovieFinder as the class that MovieLister calls.
I compile it in visual studio 2005. It compiles and starts. I creates the injection properly as far as I can tell because when it crashes I can check the value of the set method in MovieLister -- it says Spring.ExampleMovieFinder.SimpleMovieFinder. also in the output before crash it shows the list defined in SimpleMovieFinder.
Here is my program.cs, MovieLister.cs, IMovieFinder.cs, SimpleMovieFinder.cs and App.Config:
/////////////////////////////////////////////////////////////////////////////
Program.cs:
using System;
using System.Collections.Generic;
using System.Text;
using Spring.Context;
namespace Spring.ExampleMovieFinder {
class Program {
static void Main(string[] args) {
Console.WriteLine("[Program] Starting...");
Spring.Context.IApplicationContext ctx =
Spring.Context.Support.ContextRegistry.GetContext( );
Console.WriteLine("[Program] After creating ctx...");
MovieLister lister = (MovieLister)ctx.GetObject("MyMovieLister");
Console.WriteLine("[Program] After creating lister...");
String movie = lister.MoviesDirectedBy("Reservoir Dogs");
Console.WriteLine("\nSearching for movie...\n");
Console.WriteLine(movie);
Console.WriteLine("\nMovieApp Done.\n\n");
}
}
}
/////////////////////////////////////////////////////////////////////////////
MovieLister.cs:
using System;
using System.Collections.Generic;
using System.Text;
namespace Spring.ExampleMovieFinder
{
public class MovieLister
{
public MovieLister() { }
public IMovieFinder movieFinder {
set {
movieFinder = value;
}
get {
return movieFinder;
}
}
public String MoviesDirectedBy(String MovieName) {
String list = movieFinder.FindAll();
return list;
}
}
}
/////////////////////////////////////////////////////////////////////////////
IMovieFinder.cs:
using System;
using System.Collections.Generic;
using System.Text;
namespace Spring.ExampleMovieFinder
{
public interface IMovieFinder
{
String FindAll();
}
}
/////////////////////////////////////////////////////////////////////////////
SimpleMovieFinder.cs:
using System;
using System.Collections.Generic;
using System.Text;
namespace Spring.ExampleMovieFinder
{
class SimpleMovieFinder: IMovieFinder
{
private String list = "Desperado, From Dusk Till Dawn, Reservoir Dogs, Kill Bill 1, Kill Bill 2";
public SimpleMovieFinder()
{
Console.WriteLine("[SimpleMovieFinder] in constructor...");
Console.WriteLine("[SimpleMovieFinder] list: " + list);
}
public String FindAll()
{
Console.WriteLine("[SimpleMovieFinder] Find all...");
return list;
}
}
}
/////////////////////////////////////////////////////////////////////////////
App.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>
<spring>
<context>
<resource uri="config://spring/objects"/>
</context>
<objects xmlns="http://www.springframework.net">
<object name="MyMovieLister"
type="Spring.ExampleMovieFinder.MovieLister, Spring.ExampleMovieFinder">
<!-- using setter injection... -->
<property name="movieFinder" ref="MyMovieFinder"/>
</object>
<object name="MyMovieFinder"
type="Spring.ExampleMovieFinder.SimpleMovieFinder, Spring.ExampleMovieFinder">
</object>
<object name="AnotherMovieFinder"
type="Spring.ExampleMovieFinder.ColonDelimitedMovieFinde r, Spring.ExampleMovieFinder">
</object>
</objects>
</spring>
</configuration>
Here is the output:
[Program] Starting...
[SimpleMovieFinder] in constructor...
[SimpleMovieFinder] list: Desperado, From Dusk Till Dawn, Reservoir Dogs, Kill Bill 1, Kill Bill 2
Here is where it hangs for a second and comes back with StackOverFlowException.