postconstruct

@Inject and @PostConstruct not working in singleton pattern

你离开我真会死。 提交于 2019-12-23 10:18:13
问题 I have a class as below: public class UserAuthenticator { private static UserAuthenticator authenticator = @Inject private UserRepository userRepository; @PostConstruct public void init() { List<User> allUsers = userRepository.findAll(); for (User user : allUsers) { users.put(user.getEmail(), user.getPassword()); serviceKeys.put(user.getServiceKey(), user.getEmail()); } } public static UserAuthenticator getInstance() { if (authenticator == null) { authenticator = new UserAuthenticator(); }

Grails unit test fails on @PostConstruct

自古美人都是妖i 提交于 2019-12-23 05:07:16
问题 Have a @PostConstruct in the service to ensure that the dependencies have been set up. Dependencies are set in resources.groovy . Unit test fails on @PostConstruct asserts. Tried setting up the dependencies manually in setUpSpec to no avail. Even without a @TestFor , ServiceUnitTestMixin kicks in and merrily chokes on @PostConstruct . Opened a defect GRAILS-11878 which was closed promptly with an advice to use @FreshRuntime and doWithSpring . If they actually bothered to try, they'd have

@org.omnifaces.cdi.ViewScoped invokes @PostConstruct on unload of an already destroyed view

可紊 提交于 2019-12-23 02:52:54
问题 I have a problem working with @org.omnifaces.cdi.ViewScoped and multiple tabs: I have a link in TestPage.xhtml that opens another page (ShowValuePage.xhtml) with a request parameter "someValue". If I open this link 10 times in a new tab and navigate away in the first opened tab, PostConstruct will be called again instead of just navigating away. Same happens if I navigate back from ShowValuePage to TestPage multiple times. (To test this, we must click the links "Show Value" and "Home"

@Singleton bean failed to initialize because of not expected transaction status 4 when it's marked TransactionAttribute=NOT_SUPPORTED

和自甴很熟 提交于 2019-12-22 09:40:10
问题 I'm having difficulty with my EJB3.1 bean initialisation and more specifically to do with it failing due to perceived transaction rollback, even though I've marked the bean with @TransactionAttribute(NOT_SUPPORTED) . This should mean that any client transaction is paused on bean method entry until exit (when it will be resumed. It's definitely the transactional apprach I want. The "gist" of the code and error are as follows (note some of it is hand-cranked to hide details but is all relevant

calling @PostConstruct on super bean AND extending bean

妖精的绣舞 提交于 2019-12-22 04:16:42
问题 I have a BaseBean with a @PostConstruct, and a bean extending it on which i would like to call another @PostConstruct. I have read several places where it said it was possible, however, it seems the @postConstruct on the extending class is called first (if the second is called at all). I then get a NPE on "context" because I'm assuming the super bean's PostConstruct has already been called. Is this do-able? If so what am I doing wrong? Base bean: @ManagedBean @RequestScoped public class

@PostConstruct didn't get called by JSF if ManagedBean is inside jar library

与世无争的帅哥 提交于 2019-12-18 04:16:47
问题 I'm running with the following problem. I have a few Managed Beans that are shared between, at this moment, two JSF applications. As I don't want to copy and paste the code in the two (more in the coming future) I've put this shared managed beans inside a JAR library. I've followed this blog: http://jsflive.wordpress.com/2011/03/24/custom-component-library/ Well, even if I put the faces-config.xml inside JAR/META-INF/ the @ManagedBean and @ViewScoped didn't work. I couldn't realise why, but

@PostConstruct method called twice for the same request

 ̄綄美尐妖づ 提交于 2019-12-17 15:46:11
问题 I'm using JSF 2.0 with GlassFish 3.0. I have the following Managed Bean: @ManagedBean @RequestScoped public class OverviewController{ private List<Event> eventList; @PostConstruct public void init(){ System.out.println("=> OverviewController - init() - enter"); System.out.println("=< OverviewController - init() - exit"); } } From the the overview.xhtml file I'm calling different attributes or methods from my OverviewController. <ui:repeat var="event" value="#{overviewController.eventList}"> .

Why does @PostConstruct callback fire every time even though bean is @ViewScoped? JSF

匆匆过客 提交于 2019-12-17 07:14:25
问题 I am using datatable on page and using binding attribute to bind it to my backing bean. This is my code :- <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.prime.com.tr/ui"> <h:head> <title>Facelet Title</title> </h:head> <h:body> <h:form prependId="false"> <h:dataTable var=

No Session Hibernate in @PostConstruct

我的未来我决定 提交于 2019-12-12 13:32:37
问题 MyDao class have the methods to do whole persistence tasks through Hibernate SessionFactory, it works fine. I inject MyDao in MyService as can see above, but when @PostConstruct init() method is called after injected MyDao (debugging I can see MyDao well injected) get the next Hibernate exception: org.hibernate.HibernateException: No Session found for current thread My service implementation. @Service("myService") @Transactional(readOnly = true) public class MyServiceImpl implements MyService

How to test constructor of a class that has a @PostConstruct method using Spring?

被刻印的时光 ゝ 提交于 2019-12-12 09:28:59
问题 If I have a class with a @PostConstruct method, how can I test its constructor and thus its @PostConstruct method using JUnit and Spring? I can't simply use new ClassName(param, param) because then it's not using Spring -- the @PostConstruct method is not getting fired. Am I missing something obvious here? public class Connection { private String x1; private String x2; public Connection(String x1, String x2) { this.x1 = x1; this.x2 = x2; } @PostConstruct public void init() { x1 = "arf arf arf