javabeans

Auto-cast Spring Beans

删除回忆录丶 提交于 2019-11-29 09:40:15
问题 Is there a way to auto-cast Spring beans to the class defined in the application context XML? I'd like to avoid putting type information about the beans in 2 places.... in the xml configuration file and also in the code as a cast. For instance, given this config file <bean id="bean-name" class="SimpleSpringBean" scope="prototype"> <property name="myValue" value="simple value"></property> </bean> Can I call ApplicationContext.getBean("bean-name") in such a way as to avoid directly casting the

Replace spring bean in one context with mock version from another context

核能气质少年 提交于 2019-11-29 09:26:33
问题 I'm writing an integration test where an application context xml is initialized during startup. There are several test methods in the test class which make use of a specific bean 'X'(already defined in the xml). My actual requirement is to mock bean X only for one of the test methods. Inside a test method: I tried creating a separate application context using ClassPathXMLApplicationContext with only the mock bean 'M'. Now I have two Application Contexts (AC): 1. One created during test case

Purpose of Serialization in webapplication

纵饮孤独 提交于 2019-11-29 09:21:31
问题 Where is the usage of serialization in a webapplication. Is it necessary that a form bean is serializable. In tomcat what is the usage of sessions.ser file.. 回答1: 1) It is an app server dependent feature but the Servlet Spec says that if the servlet container wants to support distributed environments (sharing sessions across instances) and the like that it must accept objects that implement Serializable and be able to migrate them. Tomcat also supports storing the session state across server

JSF - Get the SessionScoped Bean instance

时间秒杀一切 提交于 2019-11-29 09:18:29
问题 I have this configuration on my web application. 2 beans : 1° Bean - It checks the login; @ManagedBean(name="login") @SessionScoped public class Login { private String nickname; private String password; private boolean isLogged; public String getNickname() { return nickname; } public void setNickname(String newValue) { nickname=newValue; } public String getPassword() { return password; } public void setPassword(String newValue) { password=newValue; } public void checkLogin() { ... i check on

Saving a PNG file on a server in a Java bean, using JSTL

橙三吉。 提交于 2019-11-29 08:59:15
I am writing an update page in JSTL where the user inputs some numbers. I then call a java bean - passing the numbers as parameters - which, using JFreeChart, creates a PNG image. All of this works fine when I save the file directly on my hard drive using ImageIO.write(myBufferedImage, "png", new File("C:/testChart.png")); I can also save the image to my tomcat directory and view it when I am running the website on my localhost. However, once this code is up on a server that is not my local host, saving to the tomcat directory won't work. How do I write this file directly to the server..say to

Get bean property getter or setter by reflection?

假如想象 提交于 2019-11-29 08:44:24
问题 Suppose I have a handle on an object of type , and I'm told by configuration that it has a bean property of type int with the name age . How can I retrieve the getter for this document? Is there a better way than prepending "get" and capitalizing the "a" in age , and looking for a method of that name via reflection? 回答1: Take a look at java.beans.Introspector. This class allows you to get the list of properties on a class. If you know property name you can call Method getter = new

Dynamic java bean from xsd

守給你的承諾、 提交于 2019-11-29 07:30:05
I have two applications, one acting as client and the other as server. In server application I generate ObjectFactory and classes using xjc from Eclipse. As a result, one of this classes is called widgetEvenCall. From the xsd: ... <xs:element name="widgetEventCall"> <xs:complexType> <xs:sequence> <xs:element minOccurs="1" maxOccurs="1" ref="tns:widgetEventDescriptor" /> <xs:element minOccurs="0" maxOccurs="unbounded" ref="tns:widgetParameter" /> </xs:sequence> </xs:complexType> </xs:element> JAXB xjc generates the classes WidgetEventCall, WidgetEventDescriptor and WidgetParameter, with their

Default method in interface in Java 8 and Bean Info Introspector

眉间皱痕 提交于 2019-11-29 06:02:28
I have a little problem with default methods in Interface and BeanInfo Introspector. In this example, there is interface: Interface public static interface Interface { default public String getLetter() { return "A"; } } and two classes ClassA and ClassB: public static class ClassA implements Interface { } public static class ClassB implements Interface { public String getLetter() { return "B"; } } In main method app prints PropertyDescriptors from BeanInfo: public static String formatData(PropertyDescriptor[] pds) { return Arrays.asList(pds).stream() .map((pd) -> pd.getName()).collect

How can I access stored values of a Bean from inside another Class

六眼飞鱼酱① 提交于 2019-11-29 03:35:10
问题 How can I implement this functionality? ApplicationConstants.phoneContacts.add( new ContactNumberBean(nameOfContact, contactNumber, contactNumberType)); ApplicationConstants and ContactNumberBean classes ContactNumberBean : package com.example.AddressBook; public class ContactNumberBean { private String nameOfContact; private String contactNumber; private int contactNumberType; public String getnameOfContact() { return nameOfContact; } public String getcontactNumber() { return contactNumber;

Declaring an array of objects in a Spring bean context

吃可爱长大的小学妹 提交于 2019-11-29 03:08:07
I'm trying to create an array of objects in a Spring context file so I can inject it to a constructor that's declared like this: public RandomGeocodingService(GeocodingService... services) { } I'm trying to use the <array> tag: <bean id="googleGeocodingService" class="geocoding.GoogleGeocodingService"> <constructor-arg ref="proxy" /> <constructor-arg value="" /> </bean> <bean id="geocodingService" class="geocoding.RandomGeocodingService"> <constructor-arg> <array value-type="geocoding.GeocodingService"> <!-- How do I reference the google geocoding service here? --> </array> </constructor-arg>