Hello all,
I've been trying to get Jersey and Spring to work nicely together for a few days now but despite my efforts I've had no luck; hopefully someone can help me out.
web.xml
spring-master.xml My 'entities' are annotated: @Service("BookBo"),etc.Code:<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:META-INF/spring-master.xml</param-value> </context-param> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>/WEB-INF/log4j.properties</param-value> </context-param> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener>
dataSource.xmlCode:<context:property-placeholder location="classpath*:META-INF/database.properties"/> <import resource="classpath*:/META-INF/dataSource.xml"/> <import resource="classpath*:/META-INF/hibernate.xml"/> <context:component-scan base-package="com.bpcm.entities"/>
hibernate.xmlCode:<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> </bean>From what I understand there are issues with dependencies when using spring-jersey, so I've excluded spring components.Code:<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <!-- <prop key="hibernate.show_sql">true</prop>--> <prop key="hibernate.hbm2ddl.auto">create-drop</prop> <prop key="hibernate.hbm2ddl.auto">create</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> <property name="annotatedClasses"> <list> <value>com.bpcm.entities.book.domain.Specialist</value> <value>com.bpcm.entities.page.domain.Aptitude</value> </list> </property> </bean>
pom.xml
If I deploy the project as an application using:Code:<properties> <jersey-version>1.8</jersey-version> <spring-version>3.0.5.RELEASE</spring-version> </properties> <dependencies> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-server</artifactId> <version>${jersey-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>com.sun.jersey.contribs</groupId> <artifactId>jersey-spring</artifactId> <version>${jersey-version}</version> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> </exclusion> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> </exclusion> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </exclusion> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> </exclusion> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>${spring-version}</version> </dependency>everything is injected properly, but if I deploy it as a webapp I get null Autowired objects. I'm not entirely sure why there is a discrepancy. I assume its working properly when ran as an app because I'm explicitly specifying the bean.Code:ApplicationContext appContext = new ClassPathXmlApplicationContext("META-INF/spring-master.xml"); BookBo BookBo = (BookBo) appContext.getBean("BookBo");
On a side note the webbapp had previously worked using Spring as the rest service, but my company wanted to switch to Jersey. Besides changing the rest controller and the dependencies the project has remained the same.
I'm sorry about the long post, I would really appreciate any help/advice,
bpcm


Reply With Quote
