Skip to main content

Posts

Showing posts with the label spring

Do I really need a service layer?

My web application is written using Spring MVC + Hibernate. My model is "Customer" entity POJO. I have got a DAO object "CustomerDAO", its method "saveCustomer(c)" contains the code interacting with Hibernate; Then I created a " CustomerService with a "saveCustomer(c)" method who simply pass the customer object to the dao for saving; Finally there are "CustomerController" and customer.jsp, who are responsible for the view layer, the jsp's form fields are bound to a Customer object on the controller side. The controller calls the service.

Why is Spring"s ApplicationContext.getBean considered bad?

I asked a general Spring question and had multiple people respond that calling Spring's ApplicationContext.getBean() should be avoided as much as possible. Why is that? How else should I gain access to the beans I configured Spring to create? I'm using Spring in a non-web application and had planned on accessing a shared ApplicationContext object as described by LiorH . Amendment I accept the answer below, but here's an alternate take by Martin Fowler who discusses the merits of Dependency Injection vs. using a Service Locator (which is essentially the same as calling a wrapped ApplicationContext.getBean() ). In part, Fowler states, " With service locator the application class asks for it [the service] explicitly by a message to the locator. With injection there is no explicit request, the service appears in the application class - hence the inversion of control. Inversion of control is a common feature of frameworks, but it's something that comes

Image is not displayed on reterival

I have a table with Images stored in it as BLOB. I'm using JPA/Hibernate. So, that Images are mapped to a bean field with type blob. Now my Spring controller is returning entire list of bean (each object of this bean has a blob object) to my jsp. I want to display all the images on that jsp. So, I tried to use some thing like this on my jsp, <c:forEach items="${itemList}" var="item" varStatus="status" > <img src="<c:out value="${item.image}" />"/><br/> /*<img src="${item.image}"/> */ </c:forEach> but that is not working. Instead of getting the list of images displayed on jsp , I 'm getting the class name, when I view the page source I saw something like this <img src="java.object.serilizableBlob@2134"/> Please help me delve with the problem. How can I display all the images on same jsp.

In a test I can find a xml, in another I can"t

I have an interesting problem, I have two web services defined in a spring-conf.xml file and I have two test classes that live in the same package and every class has its own link to this spring-conf.xml file to call their particular webservice. I am able to get beans from one of my test classes but from the other one I can't and the code is equal in both classes. In one I have this import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class WSFirstTest { private ApplicationContext context = new ClassPathXmlApplicationContext( "WEB-INF/spring-conf.xml"); private WSFirst ws = (WSFirst) context .getBean("serviceFirstDefault"); in the other one I have this import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class WSSecondTest { private ApplicationContext context2 = new ClassPath

What maven dependency need to have Class LocalContainerEntityManagerFactoryBean?

In my project class LocalContainerEntityManagerFactoryBean not found. I don't understand why? In other simple project with this class all works fine. <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="persistenceUnitName" value="simpleTest" /> <property name="dataSource" ref="dataSource" /> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="showSql" value="true" /> <property name="generateDdl" value="true" /> <property name="databasePlatform" value="org.hibernate.dialect.H2Dialect" /> </bean> </property> </bean>

JBOSS 7.1.0 error - Unable to find a public constructor for class org.jboss.resteasy.core.AsynchronousDispatcher

I am trying to migrate my spring MVC based REST application to Jboss 7.1.0. At startup, the Jboss initialisation shows that everything was started up correctly with all war files deployed successfully. I had quite a few problems getting the integration between Spring MVN and Jboss's RestEasy service and im wondering if this is another conflict between jboss resteasy with Spring MVN. When i make a request to the REST service i get the following error: 12:52:31,541 INFO [org.springframework.web.context.ContextLoader] (MSC service thread 1-5) Root WebApplicationContext: initialization completed in 3035 ms 12:52:31,845 INFO [org.jboss.web] (MSC service thread 1-5) JBAS018210: Registering web context: /MyRestService 12:52:31,875 INFO [org.jboss.as] (MSC service thread 1-5) JBAS015874: JBoss AS 7.1.0.Final "Thunder" started in 53526ms - Started 390 of 468 services (72 services are passive or on-demand) 12:52:32,034 INFO [org.jboss.as.server] (DeploymentScanner-threads

Spring 2.5 + quartz java.lang.NoClassDefFoundError: org/quartz/JobDetail

I have an issue with quartz library. I'm using it with spring 2.5: <bean id="reminderBean" class="com.mail.timexis.ReminderBean"> <property name="mailSender"> <ref local="timexisMailSender" /> </property> </bean> <bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="reminderBean" /> <property name="targetMethod" value="execute" /> </bean> <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail" ref="jobDetail" /> <!-- run every morning at 6 AM --> <property name="cronExpression" value="* * * * * ?" /> </bean>

Hibernate interceptors

I am trying to implement method described here , but can't make it work. There are no errors during compilation, but the interceptor never fired. DAO: public class GeneralInvoicesDAO { @Autowired private SessionFactory sessionFactory; @Autowired private Interceptor entityInterceptor; @Transactional public void update(GeneralInvoice object) { Session session = SessionFactoryUtils.getSession(sessionFactory, entityInterceptor, null); session.saveOrUpdate(object); } } The intercepter class: public class NewEntityInterceptor extends EmptyInterceptor implements Interceptor { /** * */ private static final long serialVersionUID = 2914362528125673753L; @Override public Boolean isTransient(Object n) { Logger logger = Logger.getLogger(getClass().getName()); try { logger.warn("test"); Boolean result = Boolean.FALSE; BaseEntity entity = (BaseEntity) n; if (enti

Why isn"t spring using my constructor to init this bean (Map parameter)

I have a spring beans configuration file where I define the following jackson classes as spring beans. For some reason on run-time the filterProvider bean is instantiated without the map argument. You can see from the docs that the SimpleFilterProvider does have such a constructor and that SimpleBeanPropertyFilter implements BeanPropertyFilter . <bean id="productAttributesAndAdvertiserNameFilter" class="org.codehaus.jackson.map.ser.impl.SimpleBeanPropertyFilter" factory-method="filterOutAllExcept"> <constructor-arg value="name"/> </bean> <bean id="offerIdFilter" class="org.codehaus.jackson.map.ser.impl.SimpleBeanPropertyFilter" factory-method="filterOutAllExcept"> <constructor-arg value="id"/> </bean> <bean id="filterProvider" class="org.codehaus.jackson.map.ser.impl.SimpleFilterProvider"> <