File tree Expand file tree Collapse file tree
test/java/org/baeldung/scopes Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,9 +8,7 @@ public Person() {
88 }
99
1010 public Person (final String name , final int age ) {
11- super ();
1211 this .name = name ;
13- this .age = age ;
1412 }
1513
1614 public String getName () {
@@ -21,17 +19,9 @@ public void setName(final String name) {
2119 this .name = name ;
2220 }
2321
24- public int getAge () {
25- return age ;
26- }
27-
28- public void setAge (final int age ) {
29- this .age = age ;
30- }
31-
3222 @ Override
3323 public String toString () {
34- return "Person [name=" + name + ", age=" + age + " ]" ;
24+ return "Person [name=" + name + "]" ;
3525 }
3626
3727}
Original file line number Diff line number Diff line change @@ -36,4 +36,10 @@ public HelloMessageGenerator sessionMessage() {
3636 return new HelloMessageGenerator ();
3737 }
3838
39+ @ Bean
40+ @ Scope (value = WebApplicationContext .SCOPE_GLOBAL_SESSION , proxyMode = ScopedProxyMode .TARGET_CLASS )
41+ public HelloMessageGenerator globalSessionMessage () {
42+ return new HelloMessageGenerator ();
43+ }
44+
3945}
Original file line number Diff line number Diff line change 99public class ScopesTest {
1010
1111 private static final String NAME = "John Smith" ;
12- private static final int AGE = 30 ;
13-
1412 private static final String NAME_OTHER = "Anna Jones" ;
15- private static final int AGE_OTHER = 40 ;
1613
1714 @ Test
1815 public void testScopeSingleton () {
@@ -22,10 +19,7 @@ public void testScopeSingleton() {
2219 final Person personSingletonB = (Person ) applicationContext .getBean ("personSingleton" );
2320
2421 personSingletonA .setName (NAME );
25- personSingletonB .setAge (AGE );
26-
2722 Assert .assertEquals (NAME , personSingletonB .getName ());
28- Assert .assertEquals (AGE , personSingletonB .getAge ());
2923
3024 ((AbstractApplicationContext ) applicationContext ).close ();
3125 }
@@ -38,10 +32,7 @@ public void testScopePrototype() {
3832 final Person personPrototypeB = (Person ) applicationContext .getBean ("personPrototype" );
3933
4034 personPrototypeA .setName (NAME );
41- personPrototypeA .setAge (AGE );
42-
4335 personPrototypeB .setName (NAME_OTHER );
44- personPrototypeB .setAge (AGE_OTHER );
4536
4637 Assert .assertEquals (NAME , personPrototypeA .getName ());
4738 Assert .assertEquals (NAME_OTHER , personPrototypeB .getName ());
You can’t perform that action at this time.
0 commit comments