localhost:8080 / user / 1というREST呼び出しを行うたびに、サーバーの起動時に作成されたオブジェクトを使用する代わりに、新しいユーザーサービスオブジェクトが作成されます。私はSpringでJerseyを使用しています。
applicationContext.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd"
default-autowire="byName"
>
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<context:annotation-config/>
<context:component-scan base-package="com.gigenginecore.platform.dataaccess.impl" />
<context:component-scan base-package="com.gigengine.dataaccess"/>
<context:component-scan base-package="com.gigengine.dataaccess.impl"/>
<context:component-scan base-package="com.gigenginecore.platform.service" />
<context:component-scan base-package="com.gigengine.service" />
<context:component-scan base-package="com.gigenginecore.provider" />
</beans>
///// UserServiceクラスのコードスニペット、スコープを強制的にシングルトンにしようとしました。
@Service
@Scope("singleton")
@Path("/user")
public class UserService extends AbstractUserService {
///from my web.xml
<servlet>
<servlet-name>jersey-servlet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.gigengine.service,com.gigenginecore.platform.service, com.gigenginecore.provider</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
/////すべてのDAOは適切にインスタンス化され、起動時にユーザーサービスクラスに挿入されますが、サービスエンドポイント自体を呼び出すと、DAOがnullの新しいUserServiceクラスが作成されます。
起動時に作成されたものを取得するために必要なことはありますか?「Spring」シングルトンのときに新しいインスタンスを作成する理由がわかりません。
助言がありますか?