- Describe the life cycle of a bean in Spring.
- What is the difference between singleton and prototype bean? Give an example when you would want to use one or the other.
- What are the advantages of using Spring?
- What are the main features of Spring?
- What is Dependency Injection/IOC?
- What are the three types of dependency injection? Which ones do Spring support?
- Name all the 7 modules of Spring and describe what they are.
- What's Bean Factory? What's Application Context? Describe the differences and when would you want to use one or the other?
- What is auto wiring? Name all five modes.
- Name two ways of accessing Hibernate using Spring.
- What is AOP?
- What is Aspect?
- What is JointPoint?
- What is Advice? Name 5 type of Advice.
- Why use declarative over programmatic transaction management?
- What are the main differences between EJB CMT and Spring's declarative transaction management?
- Does Spring's transaction management support transaction context over remote calls?
- Describe the main differences between EJB and Spring.
Showing posts with label spring. Show all posts
Showing posts with label spring. Show all posts
Sunday, 18 September 2011
Core Spring Questions
Spring questions:
Monday, 8 March 2010
Transaction Pitfalls
Just thought that I need to post this very useful article about common transaction mistakes in Java platform. It's just so easy to assume that transaction works and then in the end (or worse, in production), you find out that it does not work as intended. The classic "Transaction Rollback" mistake is surprisingly common. I've seen this again and again as people assume that this would work automatically.
Tuesday, 9 September 2008
Custom Authentication Using Spring Security
Customising Spring Security could be a challenge as there seems to be lack of practical examples. Recently I tried to customise my login page when authentication fails. I found this blog really useful: Spring Security - Using custom Authentication Processing Filter
Monday, 14 July 2008
Spring Security (Acegi) and Sitemesh
Sitemesh is a great tool to decorate your java-based web page. I am currently using it to decorate my web application so that I can have the menu on the left panel, a header, and a footer withouth worrying about including it in all my jsp pages. Spring Security (formerly known as Acegi Security System) is another great tool that I also use together with Sitemesh for authentication and authorisation. My Spring Security "authorize" tag recently did not work properly, and the problem was because in my web.xml, I declared Sitemesh BEFORE Spring Security. Spring Security would clean up before Sitemesh is able to decorate the pages, causing Spring Security tags to stop working. The solution is to declare Sitemesh after Spring Security.
Thursday, 10 April 2008
Spring JMS
Using Spring JMS to send and receive messages to Queues is not difficult nowadays. I followed this tutorial in order to communicate to IBM MQ Series with no problem. It is simple, straightforward, and you can set up your applications in a very short amount of time.
Tuesday, 19 February 2008
File Download In Spring
In order to implement a file download in Spring, the key is returning null instead of a ModelAndView object. This controller that I created below is specifically for text/ascii data. You'd need to change the content type appropriately in order to download other file types.
public class DownloadController implements Controller {
/*
* Spring dependency injection
*/
private XService xService;
public void setxService(
XService xService) {
this.xService = xService;
}
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
String idStr = request.getParameter("id");
if (idStr != null) {
long id = Long.parseLong(idStr);
String data = xService.getData(id);
doDownload(request, response, data, "file" + idStr + ".xml");
}
return null;
}
private void doDownload(HttpServletRequest request,
HttpServletResponse response, String data, String filename)
throws IOException {
int length = data.length();
ServletOutputStream op = response.getOutputStream();
response.setContentType("text/plain");
response.setContentLength(data.length());
response.setHeader("Content-Disposition",
"attachment; filename=\"" + filename + "\"");
byte[] bbuf = data.getBytes();
op.write(bbuf, 0, length);
op.flush();
op.close();
}
}
Accessing EJB 3 from Spring 2.5
Spring 2.5 now supports EJB 3 access, and it could not be any easier! Here is the spring xml snippet to achieve it:
<beans>
...
<!-- *** EJBs *** -->
<!-- REMOTE JNDI CONNECTION -->
<bean id="remoteJndiTemplate"
class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">
org.jnp.interfaces.NamingContextFactory
</prop>
<prop key="java.naming.provider.url">
localhost
</prop>
<prop key="java.naming.security.principal">
username
</prop>
<prop key="java.naming.security.credentials">
mycredentials
</prop>
</props>
</property>
</bean>
<bean id="abstractRemoteSlsb" abstract="true"
class="org.springframework.ejb.access.
SimpleRemoteStatelessSessionProxyFactoryBean">
<property name="lookupHomeOnStartup" value="false">
<property name="jndiTemplate">
<ref bean="remoteJndiTemplate" />
</property>
</bean>
<bean id="myService" parent="abstractRemoteSlsb">
<property name="jndiName"
value="myapp/MySessionBeanImpl/remote">
<property name="businessInterface"
value="au.com.package.name.MySessionBean">
</bean>
...
</beans>
Friday, 12 January 2007
Spring, Hibernate, Lazy Loading, and Sessions
Recently I've developed a Spring application to notify users based on certain conditions on data extracted from an ERP system using Hibernate. I had a LazyInitializationException problem when looping through some hibernate objects, because the connection had already been closed i.e. The service layer had finished it's job and therefore closed the connection. The hibernate object became detached, and since I specified lazy to true, I got the LazyInitializationException.
Since it is not a web app, I cannot use OpenInSessionViewInterceptor or OpenInSessionViewFilter, so I figured out that I had to use some manual code to keep the session open. Here is the code to solve the issue:
private static SessionFactory sessionFactory;
private static ApplicationContext init() {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
sessionFactory = (SessionFactory) context.getBean("sessionFactory");
Session session = SessionFactoryUtils.getSession(sessionFactory, true);
TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
return context;
}
private static void end() {
if (sessionFactory != null) {
SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.unbindResource(sessionFactory);
SessionFactoryUtils.closeSession(sessionHolder.getSession());
}
}
Friday, 22 December 2006
Spring In Action

This is an excellent book for anyone wanting to jump into Spring. It provides an excellent introduction, sample application, as well as the core Spring features and what made it a very popular framework today. This book covers the new Spring 2.0 features. I loved this book! 4 out of 5!
Subscribe to:
Posts (Atom)