spring

Dependency Injection into your Singleton

I have a singleton that has a spring injected Dao (simplified below): public class MyService<T> implements Service<T> { private final Map<String, T> objects; private static MyService instance; MyDao myDao; public void set MyDao(MyDao myDao) { this. myDao = myDao; } private MyService() { this.ob...

Spring/Hibernate/Junit example of testing DAO against HSQLDB

Hi guys, I'm working on trying to implement a JUnit test to check the functionality of a DAO. (The DAO will create/read a basic object/table relationship). The trouble I'm having is the persistence of the DAO (for the non-test code) is being completed through an in-house solution using Spring/Hibernate, which eliminates the usual *.hb...

Creating multiple forms in one jsp file. ModelAttributes have to always be set?

I am new to Spring and have been reading about it the last few days. I haven't found an open source example like this so far and didn't see a clear way for it to be done. Many sites have a login or search box that is on every page. If this is the case, how can you avoid setting an attribute in a model on every page for that form? Simila...

How to create TestContext for Spring Test?

Newcomer to Spring here, so pardon me if this is a stupid question. I have a relatively small Java library that implements a few dozen beans (no database or GUI). I have created a Spring Bean configuration file that other Java projects use to inject my beans into their stuff. I am now for the first time trying to use Spring Test to inj...

Where to open sessions in a Spring/Hibernate stack?

I'm trying to figure out a good design for a Spring/Hibernate app. When creating such an app, it appears like there are a handful of major decisions. The first major decision seems to be where to put the session/transaction boundary. It seems like I have 3 major choices: as a filter before controllers are even invoked, immediately bel...

Spring @Transactional method - participating transaction

in one dao I have 2 @Transactional methods. if i do not provide any explicit properties, then what will happen, if I run one method in the body of another? Both methods will run within THE SAME ONE TRANSACTION? ...

Spring Test / JUnit problem - unable to load application context

I am using Spring for the first time and must be doing something wrong. I have a project with several Bean implementations and now I am trying to create a test class with Spring Test and JUnit. I am trying to use Spring Test to inject a customized bean into the test class. Here is my test-applicationContext.xml: <?xml version="1.0" e...

How to make a thread try to reconnect to the Database x times using JDBCTemplate

Hi, I have a single thread trying to connect to a database using JDBCTemplate as follows: JDBCTemplate jdbcTemplate = new JdbcTemplate(dataSource); try{ jdbcTemplate.execute(new CallableStatementCreator() { @Override public CallableStatement createCallableStatement(Connection con) throws SQLException { ...

BindingResult.rejectValue does not find value from ValidationMessages.properties

We're using spring with annotations, and our annotated fields get validated fine and error messages get displayed from ValidationMessages.properties, but for custom validation message from ValidationMessages.properties does not seem to be used. Here's the example: Validatior (also the form): public void validateSpecial(BindingResult...

JMS On demand Support Active MQ with Spring

I am involving in SMS Gate way project. The Very Base function is our system have couple of Customers They will send their request to our gateway in a form of XML. Those request is Process first and send it to a common out bound JMS(ActiveMQ 5.3 ) There is an listener running on which should be capable of doing the following Retr...

Instantiating spring beans in dynamically created classes.

I am dynamically creating classes which contain spring beans, however the beans are not getting instantiated or initialised, leaving them as null. How do I make sure that a dynamically created class creates all of its spring beans properly? This is how I am dynamically creating the class: Class ctransform; try { ctransform = Class...

Spring / Hibernate project with Tomcat and JQuery.

Hi, I have a Dynamic Web Project that implements Spring and Hibernate using a Tomcat Server (v6). I'm lauching Tomcat with my Eclipse Galileo and I'm not getting any errors in the console but Tomcat is rendering my webpages randomly. The page just keep loading but without displaying anything, there's nothing on the console either. When...

Spring/Eclipse 'referenced bean not found' warning when using <import>?

I have just broken up a Spring bean configuration file into smaller external files and have used the the "import" directive to include them in my Spring Test application context XML file. But whenever I reference one of the beans from the imported files I get a warning within Eclipse/STS/Spring XML editor complaining that "referenced be...

Embedded ActiveMQ broker in Spring/OSGi problems.

Hello fellows, I ran into a very disturbing issue that's been puzzling me for a while and I was wondering if anyone could give me some insight on this. Basically, what I'm trying to do is set up an embedded ActiveMQ broker in the Spring context of one of my OSGi bundles (in Felix). I have downloaded the bundle and all dependencies list...

No flow definition found. Spring web flow

Hi, I am new to Spring webflow and now I am trying the example in Spring recipes book and I know this is a basic question. I am getting the error as follows, org.springframework.webflow.definition.registry.NoSuchFlowDefinitionException: No flow definition '${flowExecutionUrl}&_eventId=next' found at org.springframework.webflo...

Up to date, JPA compliant GenericDAO Implementation

I read this article: http://www.ibm.com/developerworks/java/library/j-genericdao.html several times and believe I understand what it is saying. However, it is 4 years old and I have a JPA compliant Java application to contend with. In addition, I see that there is a JPATemplate in Spring that has some good functionality, but the Spri...

Caching with Spring Framework

Spring Modules had a @Cacheable annotation: org.springmodules.cache.annotations.Cacheable Now that Spring Module is deprecated, what is the recommendation for caching? And is still still possible to work with ehCache? ...

@ExceptionHandler doesn't handle the thrown exceptions

Hello, I have a method in my controller which will handle the exceptions thrown by the application. So I have a method like this one. @Controller public class ExceptionController { @RequestMapping(value="/error") @ExceptionHandler(value={Exception.class, NullPointerException.class}) public String showError(Exception e){ ...

I'm using spring, hibernate and mysql. How can I let my app create the table automatically.

Hi guys, I'm using spring, all my annotated entity class information are put in the ApplicationContext.xml. I'm using a MySql database, now how can I use the SchemaExport function in hibernate to create the tables? My application can't create the table automatically, though i have set <prop key="hbm2ddl.auto">create</prop>. This is my A...

Why is it possible to save entity but not delete if transactional annotation is set to readonly=true with Hibernate?

Hello experts! My class is annotated with org.springframework.transaction.annotation.Transactional like this: @Transactional(readOnly = true) public class MyClass { I then have a dao class: @Override public void delete(final E entity) { getSession().delete(entity); } @Override public void save(final E entity) { getSession(...