0
我試圖自動連線一個bean,當我嘗試這樣做時它總是空的。無論我如何嘗試(自動或構造函數/屬性注入)它總是空。啓動時的Spring bean null
我該做什麼不正確的事?
package com.ricki.relocate.service;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import org.springframework.beans.factory.annotation.Autowired;
import com.ricki.relocate.database.RelocateServiceDaoImpl;
@Path("/service")
public class Service {
@Autowired
private RelocateServiceDaoImpl service;
@Path("/createUser")
@GET
@Produces("application/json")
public String createUser(@QueryParam("firstname") String firstname, @QueryParam("lastname") String lastname, @QueryParam("username") String username, @QueryParam("password") String password) {
boolean result = service.createNewUser(firstname, lastname, username, password);
return Boolean.toString(result);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd ">
<!-- Initialization for data source -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/Relocate" />
<property name="username" value="" />
<property name="password" value="" />
</bean>
<!-- Definition for RelocateServiceDaoImpl bean -->
<bean id="relocateServiceDaoImpl" class="com.ricki.relocate.database.RelocateServiceDaoImpl">
<constructor-arg index="0" ref="dataSource" />
</bean>
<!-- Definition for service bean which uses dao bean -->
<bean id="service" class="com.ricki.relocate.service.Service">
<property name="relocateServiceDao" ref="relocateServiceDaoImpl" />
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>CrunchifyRESTJerseyExample</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/relocate/*</url-pattern>
</servlet-mapping>
</web-app>
Spring不會自動的注入新澤西州的字段/方法/構造函數(或任何JAXRS實現,這是)管理對象。你有沒有建立兩者的適當整合? –
不,我沒有 - 我正在按照我現在已經偏離的教程 – Biscuit128
這可能是問題所在。尋找Spring-Jersey橋。 –