javabeans

Best way to manually pull a spring bean?

我的梦境 提交于 2019-12-10 12:05:47
问题 How do I pull a spring bean manually? I have a rather large web application, and in a given service, a transient object requires access to a bean that is machine specific (database connection info.) Since the application runs in a cluster, this transient object (which can bounce between servers) always needs to grab the correct connection been from the current spring context and server. So, what's the best way to manually pull a bean out of spring? 回答1: You could have your service implement

JavaEE Wildfly EJB not injected, war-only project

怎甘沉沦 提交于 2019-12-10 10:55:58
问题 I'm new to JavaEE and I created a "hello world" project, using Hibernate as JPA provider, build using gradle and deployed to Wildfly . I want to use @Stateless bean for database-aware class, that will do all operations on DB, and then inject it to all "JAX-RS" classes, that contain REST endpoints. Database class: @Stateless public class DatabaseManager { @PersistenceContext EntityManager entityManager; public DatabaseManager() { } public String sayHello() { // do some db-stuff return "EHLO";

How can I handle a POJO like a bean?

狂风中的少年 提交于 2019-12-10 10:36:19
问题 How can I access a simple java object as a bean? For example: class Simple { private String foo; String getFoo() { return foo; } private void setFoo( String foo ) { this.foo = foo; } } Now I want to use this object like this: Simple simple = new Simple(); simple.setFoo( "hello" ); checkSettings( simple ); So I'm looking for the implementation of the method checkSettings( Object obj ) : public boolean checkSettings( Object obj ) { // pseudocode here Bean bean = new Bean( obj ); if( "hello"

Java 8 Setting global time formatters

我与影子孤独终老i 提交于 2019-12-10 03:03:43
问题 I want to set my own DateTimeFormatter as the global formatter. When I do the following line: ZonedDateTime.now(); I get: 2016-03-30T08:58:54.180-06:00[America/Chicago] If I do this: ZonedDateTime.now().format(DateTimeFormatter.RFC_1123_DATE_TIME) I get: Wed, 30 Mar 2016 9:00:06 -0600 I want what's printed above but with am/pm so I made my custom formatter and printed out the time like so: DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss a Z");

Gwt editor with not only getter/setter bean class

纵然是瞬间 提交于 2019-12-09 21:30:05
问题 Lets say I have form build in GWT, an UI-Binder, which implements Editor interface (com.google.gwt.editor.client.Editor) with two date fields (date from and to). Bean class is expected to have members: Date fromDate; // with getter and setter Date toDate; // with getter and setter And okay, while having bean class defined as written, there is no problem, but just after I add something like this: public boolean hasFromDate() { return fromDate != null; } I got compilation error (for example for

Spring beans DTD and XMLNS

二次信任 提交于 2019-12-09 08:58:55
问题 When i am creating a spring project I always have problem with XLMNS. what is exactly XMLNS? what are these actually? <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema

BeanUtils.cloneBean() deep copy

拜拜、爱过 提交于 2019-12-09 07:55:38
问题 If all the objects within the bean implement Serializable interface, will BeanUtils.cloneBean() do a deep copy? 回答1: No, cloneBean() does shallow copy only. If you want deep copy. You may refer this link which has technique to do deep copy. 回答2: Use SerializationUtils.clone method from the Apache Commons Lang for the deep copy . It copies the entire class hierarchy. SerializationUtils.clone(object); 回答3: There is also another java library which supports both shallow cloning and deep cloning.

java listen to ContextRefreshedEvent

时间秒杀一切 提交于 2019-12-09 05:45:12
问题 I have a classX in my spring application in which I want to be able to find out if all spring beans have been initialized. To do this, I am trying to listen ContextRefreshedEvent. So far I have the following code but I am not sure if this is enough. import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; public classX implements ApplicationListener<ContextRefreshedEvent> { @Override public void onApplicationEvent

OpenCSV CSV to JavaBean

强颜欢笑 提交于 2019-12-09 01:57:39
问题 If I have a class with non-primitive public members and I want to populate them from a CSV file with OpenCSV, how can I do this? I notice that OpenCSV has some protected members relating to PropertyDescriptors So let's say I have a Person class that has an Address member, and my CSV file contains the detailsd for each person including their address.. Person{ private String name; private Address al public void setAddress(Address a){..} public void setName(String name){..} } Addess{ private

Getting a GET request param into an @ViewScoped bean

好久不见. 提交于 2019-12-09 01:08:39
问题 I have a (request-scoped) list from which the user may select a "PQ" (list of links). When clicked or otherwise entered into the browser the main page for each PQ shall be displayed. Each PQ's page is of the form http://localhost:8080/projectname/main.jsf?id=2 Here's the PQ bean first: @Named @ViewScoped public class PqHome implements Serializable { @PersistenceContext(unitName="...") private EntityManager em; private Integer id; private PQ instance; @PostConstruct public void init() { System