Skip to content

Commit

Permalink
Fix Spring Hibernate Jersey Integration Problems
Browse files Browse the repository at this point in the history
  • Loading branch information
vbc00297 authored and vbc00297 committed Jun 14, 2010
1 parent 0db266b commit ecac644
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 13 deletions.
Binary file added WebContent/WEB-INF/lib/antlr-2.7.6.jar
Binary file not shown.
Binary file added WebContent/WEB-INF/lib/jersey-spring-1.2.jar
Binary file not shown.
17 changes: 15 additions & 2 deletions WebContent/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>

<servlet>
<!--
Parameter used by Spring to locate its context configuration used for creating
a WebApplicationContext.
-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>

<servlet>
<servlet-name>Jersey Hibernate Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>example.resources</param-value>
Expand Down Expand Up @@ -93,4 +102,8 @@
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

</web-app>
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
default-autowire="byName">

<context:component-scan base-package="example.dao" />
<context:component-scan base-package="example.service" />
<context:component-scan base-package="example.resources" />
<context:component-scan base-package="example.data" />
<context:component-scan base-package="example.dao"/>
<context:component-scan base-package="example.service"/>
<context:component-scan base-package="example.data"/>
<context:component-scan base-package="example.resources"/>

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass">
Expand Down Expand Up @@ -57,11 +57,14 @@
</props>
</property>
</bean>


<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven />





</beans>
4 changes: 4 additions & 0 deletions src/example/data/Word.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public class Word implements Serializable {
@Column(nullable = false)
private Integer points;

public Word () {
value = "";
points = new Integer(0);
}
public Word (String aValue, Integer aPoints){
this.value = aValue;
this.points = aPoints;
Expand Down
10 changes: 6 additions & 4 deletions src/example/resources/Administer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

Expand All @@ -36,19 +37,20 @@
import example.data.WordList;
import example.service.DictionaryService;
import example.service.DictionaryServiceImpl;
// The Java class will be hosted at the URI path "/hibernate/Administer"
// The Java class will be hosted at the URI path "/hibernate"
@Path("/")
@Component
@Scope("request")

public class Administer {
@Context
UriInfo uriInfo;
@Context
Request request;
@Context HttpServletRequest servletRequest;
@Inject private DictionaryDaoImpl dictionaryDao;
@Inject private DictionaryServiceImpl dictionaryService;

@Inject private DictionaryDao dictionaryDao;
@Inject private DictionaryService dictionaryService;

@GET
@Path("list")
Expand Down
2 changes: 1 addition & 1 deletion src/example/service/DictionaryServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@Service
@Transactional
public class DictionaryServiceImpl implements DictionaryService {
private DictionaryDaoImpl dictionaryDao;
private DictionaryDao dictionaryDao;

public void updateWord(Word word) {
dictionaryDao.updateWord(word);
Expand Down

0 comments on commit ecac644

Please sign in to comment.