Re: Java Singleton , Framework Design Patterns
You have been very helpful. Your information is very much along the same lines I was headed. Best Regards Zahid On Sat, 14 Dec 2019 at 12:19, Martin Gainty wrote: > MG>maybe.. see below > > > From: Zahid Rahman > Sent: Friday, December 13, 2019 5:09 PM > To: Struts Users Mailing List > Subject: Re: Java Singleton , Framework Design Patterns > > Hi, > > >?am interested to know which topic prompts your question ? > As you can see from the log file (below) the spring framework creates and > destroys a singleton of a bean. > So the singleton pattern is used by the container. > I was also informed that the singleton is used to create a login screen. > That also appears to be the case from the page > http://www.blackwasp.co.uk/Singleton.aspx. > > The login screen I will be using is the login.java and login.jsp in the > struts2 "blank app" in "struts-examples-master". > The struts framework also helps me with duplicate form submission. > So do I need to use the singleton pattern ? > > MG>here is ted husted struts-blank login.java (un-edited) > /* > * $Id: Login.java 471756 2006-11-06 15:01:43Z husted $ > * > * Licensed to the Apache Software Foundation (ASF) under one > * or more contributor license agreements. See the NOTICE file > * distributed with this work for additional information > * regarding copyright ownership. The ASF licenses this file > * to you under the Apache License, Version 2.0 (the > * "License"); you may not use this file except in compliance > * with the License. You may obtain a copy of the License at > * > * http://www.apache.org/licenses/LICENSE-2.0 > * > * Unless required by applicable law or agreed to in writing, > * software distributed under the License is distributed on an > * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > * KIND, either express or implied. See the License for the > * specific language governing permissions and limitations > * under the License. > */ > package example; > public class Login extends ExampleSupport { > public String execute() throws Exception { > if (isInvalid(getUsername())) return INPUT; > if (isInvalid(getPassword())) return INPUT; > return SUCCESS; > } > private boolean isInvalid(String value) { > return (value == null || value.length() == 0); > } > private String username; > public String getUsername() { > return username; > } > public void setUsername(String username) { > this.username = username; > } > private String password; > public String getPassword() { > return password; > } > public void setPassword(String password) { > this.password = password; > } > } > > //no singleton yet as there is no public static ClassName getInstance() > //with private constructor pointing to getInstance() > > //BUT singleton is used to instantate and set default ObjectFactory for > XmlConfigurationProvider > //as seen here in ConfigurationTestBase.java > package com.opensymphony.xwork2.config.providers; > public abstract class ConfigurationTestBase extends > com.opensymphone.xwork2.XWorkTestCase { > protected com.opensymphony.xwork2.config.ConfigurationProvider > buildConfigurationProvider(final String filename) { > configuration = new > com.opensymphony.xwork2.config.providers.MockConfiguration(); > > ((com.opensymphony.xwork2.config.providers.MockConfiguration)configuration).selfRegister(); > container = configuration.getContainer(); > XmlConfigurationProvider prov = new > XmlConfigurationProvider(filename, true); > > prov.setObjectFactory(container.getInstance(com.opensymphony.xwork2.ObjectFactory.class)); > > //but the provider does not use Spring Object Factory which we can remedy > here > > prov.setObjectFactory(container.getInstance(com.opensymphony.xwork2.spring.SpringObjectFactory.class)); > > //as you mention we must follow springs example of declaring singleton > bean in ./WEB-INF/context.xml > > http://www.springframework.org/dtd/spring-beans.dtd";> > > class="com.opensymphony.xwork2.spring.SpringObjectFactory" singleton="true" > /> > > //where struts specifies default ObjectFactory thru > ./classes/org/apache/struts2/default.properties > ### if specified, the default object factory can be overridden here > ### Note: short-hand notation is supported in some cases, such as "spring" > ### Alternatively, you can provide a > com.opensymphony.xwork2.ObjectFactory subclass name here > > struts.objectFactory=com.opensymphony.xwork2.spring.SpringObjectFactory.class > > //the line > struts.objectFactory=com.opensymphony.xwork2.spring.SpringObjectFactory.class > in default.properties should be sufficient > //to route all instances of ObjectFactory to SpringObjectFactory > > does this help? > > 2019-12-13 21:01:06,882 [main] [DEBUG] > o.s.b.f.s.DefaultListableBeanFactory - Pre-instantiating singletons in > > org.springframewor
Re: Java Singleton , Framework Design Patterns
MG>maybe.. see below From: Zahid Rahman Sent: Friday, December 13, 2019 5:09 PM To: Struts Users Mailing List Subject: Re: Java Singleton , Framework Design Patterns Hi, >?am interested to know which topic prompts your question ? As you can see from the log file (below) the spring framework creates and destroys a singleton of a bean. So the singleton pattern is used by the container. I was also informed that the singleton is used to create a login screen. That also appears to be the case from the page http://www.blackwasp.co.uk/Singleton.aspx. The login screen I will be using is the login.java and login.jsp in the struts2 "blank app" in "struts-examples-master". The struts framework also helps me with duplicate form submission. So do I need to use the singleton pattern ? MG>here is ted husted struts-blank login.java (un-edited) /* * $Id: Login.java 471756 2006-11-06 15:01:43Z husted $ * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package example; public class Login extends ExampleSupport { public String execute() throws Exception { if (isInvalid(getUsername())) return INPUT; if (isInvalid(getPassword())) return INPUT; return SUCCESS; } private boolean isInvalid(String value) { return (value == null || value.length() == 0); } private String username; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } private String password; public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } //no singleton yet as there is no public static ClassName getInstance() //with private constructor pointing to getInstance() //BUT singleton is used to instantate and set default ObjectFactory for XmlConfigurationProvider //as seen here in ConfigurationTestBase.java package com.opensymphony.xwork2.config.providers; public abstract class ConfigurationTestBase extends com.opensymphone.xwork2.XWorkTestCase { protected com.opensymphony.xwork2.config.ConfigurationProvider buildConfigurationProvider(final String filename) { configuration = new com.opensymphony.xwork2.config.providers.MockConfiguration(); ((com.opensymphony.xwork2.config.providers.MockConfiguration)configuration).selfRegister(); container = configuration.getContainer(); XmlConfigurationProvider prov = new XmlConfigurationProvider(filename, true); prov.setObjectFactory(container.getInstance(com.opensymphony.xwork2.ObjectFactory.class)); //but the provider does not use Spring Object Factory which we can remedy here prov.setObjectFactory(container.getInstance(com.opensymphony.xwork2.spring.SpringObjectFactory.class)); //as you mention we must follow springs example of declaring singleton bean in ./WEB-INF/context.xml http://www.springframework.org/dtd/spring-beans.dtd";> //where struts specifies default ObjectFactory thru ./classes/org/apache/struts2/default.properties ### if specified, the default object factory can be overridden here ### Note: short-hand notation is supported in some cases, such as "spring" ### Alternatively, you can provide a com.opensymphony.xwork2.ObjectFactory subclass name here struts.objectFactory=com.opensymphony.xwork2.spring.SpringObjectFactory.class //the line struts.objectFactory=com.opensymphony.xwork2.spring.SpringObjectFactory.class in default.properties should be sufficient //to route all instances of ObjectFactory to SpringObjectFactory does this help? 2019-12-13 21:01:06,882 [main] [DEBUG] o.s.b.f.s.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@6f1d30d: defining beans [numberGenerator]; root of factory hierarchy 2019-12-13 21:01:06,882 [main] [DEBUG] o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'numberGenerator' 2019-12-13 21:01:06,882 [main] [DEBUG] o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'numberGenerator' 2019-12-13 21:01:06,895 [main] [DEBUG] o.s.b.f.s.DefaultListableB
RE: have plan to upgrade version of spring in struts 2 Spring plugin?
Hi, Thank you so much! Yes we will upgrade Spring gradually during Struts 2.6.x releases - Struts 2.5 is under maintenance mode only for security releases. However, recent Struts 2.5.22 uses Spring 4.3.25.RELEASE [1]; doesn't it work for you? Regards. [1] https://mvnrepository.com/artifact/org.apache.struts/struts2-core/2.5.22 >-Original Message- >From: Sai Man Yau >Sent: Wednesday, December 11, 2019 7:58 AM >To: user@struts.apache.org >Subject: have plan to upgrade version of spring in struts 2 Spring plugin? > >Dear Struts 2 Team, > >Thanks for your hard work to maintain such great framework to sustain all other >developers. Thanks!! > >Since struts is using spring is some of the component, I would like to ask >will there >a plan to upgrade the spring dependencies for Struts 2 Spring plugin because of >the Spring has officially announced most of the versions will be EOL in coming >years. Thanks. > >Reference quote: >"The current version (2.5.10.1) of the Struts 2 Spring plugin has transitive >dependencies to the Spring 4.1.6.RELEASE version. " > >Regards, >Simon > >- >To unsubscribe, e-mail: user-unsubscr...@struts.apache.org >For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org