spring

What is the best book to learn Spring and Hibernate

I would like to learn Spring and Hibernate in an efficient way. Next weeks, I will have a lot of time to read but I will not be in front of a computer (so it will difficult to read online tutorials for example). So, my question is : what is the best book to learn Spring and Hibernate ? Of course, I know that I'll have to practice a li...

Automatic configuration reinitialization in Spring

In Log4j, there is a feature wherein the system can be initialized to do a configure and watch with an interval. This allows for the log4j system to reload its properties whenever the property file is changed. Does the spring framework have such a Configuration Observer facility wherein the Configuration is reloaded when it changed. The ...

Where should I put application configuration files for a Maven project?

I'm using the Maven Application Assembler plugin to generate stand-alone executables from my Java project. The application reads in configuration files, including Spring files. The Application Assembler plugin has an option (activated by default) to add a etc/ directory to the application's classpath, but what should I do to have the plu...

Access Spring beans from a servlet in JBoss

I want to write a simple servlet in JBoss which will call a method on a Spring bean. The purpose is to allow a user to kick off an internal job by hitting a URL. What is the easiest way to get hold of a reference to my Spring bean in the servlet? JBoss web services allow you to inject a WebServiceContext into your service class using a...

Hibernate session handling in spring web services

I am using spring-ws with Jaxb2Marshaller, PayloadRootAnnotationMethodEndpointMapping and GenericMarshallingMethodEndpointAdapter to configure my web services via the @Endpoint and @PayloadRoot annotations. When I try to use the DAO's of my project I am able to load objects from the database but as soon as I try to access properties ins...

Spring and hibernate.cfg.xml

How do I get Spring to load Hibernate's properties from hibernate.cfg.xml? We're using Spring and JPA (with Hibernate as the implementation). Spring's applicationContext.xml specifies the JPA dialect and Hibernate properties: <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"> <propert...

Effects of incorrect spring initialization

I'm working with an incorrectly built spring application. Rather than use IOC, objects that require references are pulling their references from the context: BeanFactory b = SingletonBeanFactoryLocator.getInstance(). useBeanFactory("factory").getFactory(); Bean foo = (FOO)beanFactory.getBean("foo"); Putting asid...

Hibernate second level cache with Spring

I'm using Spring + JPA + Hibernate. I'm trying to enable Hibernate's second level cache. In my Spring's applicationContext.xml I have: <prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.SingletonEhCacheProvider</prop> <prop key="hibernate.cache.provider_configuration_file_resource_path">/ehcache.xml</prop> When I run ...

Connect to a Read Only database

While trying to connect to a database that's set to read only, the connection cannot be made. I get the following error: Cannot create PoolableConnectionFactory (Io exception: The Network Adapter could not establish the connection) The application needs to run in read-write mode and then automatically handle the switch to read-only ...

Getting Spring Application context from a non bean object without using Singleton

I need to get the spring application context from a non bean object. In another thread in SO, the accepted answer suggests to use singleton to get the application context. Getting Spring Application Context But using singleton makes my code more coupled and less testable, the usual problems discussed in many threads (e.g. What is so bad...

Is there a PropertyPlaceholderConfigurer-like class for use with Spring that accepts XML?

Spring has a very handy convenience class called PropertyPlaceholderConfigurer, which takes a standard .properties file and injects values from it into your bean.xml config. Does anyone know of a class which does exactly the same thing, and integrates with Spring in the same way, but accepts XML files for the config. Specifically, I'm t...

Building a data layer using Spring JdbcTemplate

Do you know of any resources that describe building a data access layer using Spring's JdbcTemplate classes? I'm looking for something beyond the basics described in the Spring framework documentation. ...

How to solve refreshing issues in Facelets and Spring Web Flow?

For my particular project, I'm using Facelets (1.1.14), MyFaces (1.2.3), and Spring Web Flow (2.0.3). My IDE is JDeveloper 10.1.3.3. My browser is IE6 (work requirement). Okay...ran into a very weird issue today. Normally, when I'm using Facelets, I can make whatever changes I want to my xhtml file, refresh my browser window, and s...

Java web application properties

Does Java and/or Spring have the concept of properties? I have bunch of domain models, each of which has several properties. Example: public class Person { private String name; private Date dateOfBirth; private float height; private float weight; // getters and setters not shown } When displaying a person, the prop...

Spring MVC validation with Annotations

I'm having quite some trouble since I migrated my controllers from classical inheritance to use the annotations like @Controller and @RequestMapping. The problem is that I don't know how to plug in validation like in the old case. Are there any good tutorials about this? ...

Is there a recommend way to get Spring 2.5+ to autowire Hibernate domain objects

Is there a recommend way to get Spring 2.5+ to autowire Hibernate (3.0+) domain objects. I realize that there is a way to do this using AspectJ (@Configurable), but I would like to avoid pulling in AspectJ. Some Googling found this DependencyInjectionInterceptorFactoryBean class but it seems to just live in the sandbox (and just in 2.0....

Best way to validate URL parameters in Spring MVC website?

I am using Spring MVC to build my web application, and I have a question about validating parameters I receive in the URL. What is the best way to detect invalid parameters and display errors to the user? Suppose I have a "View User Profile" page. The profile that is displayed is based on a user ID parameter specified in the URL. I migh...

Lazy Loading DTO fields in Spring

I have a project that is using Spring and is broken down into a couple dozen DAOs and associated DTOs. I'm using JdbcTemplate, but not much else, as it's exactly the level of abstraction I'm happy with. I'm currently performing lazy loading on my DTOs by placing some rather hairy code in their getters. Basic boilerplate logic is: 1....

Using Spring Pitchfork to have JEE compliant code that runs in non-JEE container

I am facing the decision to abandon Java EE 5 (JEE) container to use web container instead (with Spring). According to Interface21 Spring Pitchfork allows elements of the JEE programming model to be used in Spring. Thus, I get a subset of JEE annotations inside of Spring container. Since I prefer to maintain compatibility with JEE this l...

AOP for third-party classes

I have used AOP within spring with no real problems, mainly for transaction management, for which it works a charm. My question is this... the only examples I've seen for AOP so far is to pointcut a class that you have created yourself. Is it possible to pointcut a class within a third party library, for example a database connection c...