Proxy concrete class not working as expected in v 3.2.0
Hi guys,
I'm using Jersey, and Spring for AOP. In the rest tier, I need to set my proxy target type to be of the target class. This is due to resources not using interfaces (as expected). Otherwise jersey blows up when proxying. However, I'm receiving strange errors on bean scope. Specifically, I'm receiving this error. As you can see, the scope is singleton, so I'm a bit confused why I'm receiving this error. Any thoughts?
V 3.2.0.RELEASE
Thanks!
Todd
Code:
SEVERE: service exception:
java.lang.RuntimeException: The scope of the component class org.usergrid.rest.JacksonCustomMapperProvider must be a singleton
at com.sun.jersey.core.spi.component.ioc.IoCProviderFactory.wrap(IoCProviderFactory.java:102)
at com.sun.jersey.core.spi.component.ioc.IoCProviderFactory._getComponentProvider(IoCProviderFactory.java:93)
at com.sun.jersey.core.spi.component.ProviderFactory.getComponentProvider(ProviderFactory.java:153)
at com.sun.jersey.core.spi.component.ProviderServices.getComponent(ProviderServices.java:251)
at com.sun.jersey.core.spi.component.ProviderServices.getProviders(ProviderServices.java:148)
at com.sun.jersey.core.spi.factory.ContextResolverFactory.init(ContextResolverFactory.java:83)
at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1271)
at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:169)
at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:775)
at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:771)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:771)
at com.sun.jersey.spi.spring.container.servlet.SpringServlet.initiate(SpringServlet.java:117)
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318)
at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609)
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
at javax.servlet.GenericServlet.init(GenericServlet.java:241)
at org.glassfish.grizzly.servlet.ServletHandler.loadServlet(ServletHandler.java:448)
at org.glassfish.grizzly.servlet.ServletHandler.doServletService(ServletHandler.java:373)
at org.glassfish.grizzly.servlet.ServletHandler.service(ServletHandler.java:330)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:163)
at org.glassfish.grizzly.http.server.HttpHandlerChain.service(HttpHandlerChain.java:195)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:163)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:158)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:286)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:223)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:155)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:134)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:78)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:827)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:103)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:111)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:131)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:508)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:488)
at java.lang.Thread.run(Thread.java:680)
Class
Code:
@Provider
@Component
@Scope("singleton")
@Produces({ MediaType.APPLICATION_JSON })
public class JacksonCustomMapperProvider implements
ContextResolver<ObjectMapper> {
private static final Logger logger = LoggerFactory
.getLogger(JacksonCustomMapperProvider.class);
public final static Annotations[] BASIC_ANNOTATIONS = { Annotations.JACKSON };
MapperConfigurator _mapperConfig;
public JacksonCustomMapperProvider() {
logger.info("JacksonCustomMapperProvider installed");
_mapperConfig = new MapperConfigurator(new ObjectMapper(),
BASIC_ANNOTATIONS);
_mapperConfig.setAnnotationsToUse(BASIC_ANNOTATIONS);
// do configuration of mapper here
_mapperConfig
.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
_mapperConfig.configure(
SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
}
@Override
public ObjectMapper getContext(Class<?> aClass) {
return _mapperConfig.getConfiguredMapper();
}
public MapperConfigurator getConfigurator() {
return _mapperConfig;
}
}
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<import resource="classpath:/usergrid-services-context.xml" />
<!-- we need to scope our proxy as our target class since we're not using interfaces for resources -->
<context:component-scan base-package="org.usergrid.rest" scoped-proxy="targetClass" />
<bean id="serverEnvironmentProperties" class="org.usergrid.rest.ServerEnvironmentProperties">
<constructor-arg ref="properties" />
</bean>
<bean id="apiResponse" class="org.usergrid.rest.ApiResponse"/>
<bean
class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
depends-on="lifecycleBeanPostProcessor" />
<bean
class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
<property name="securityManager" ref="securityManager" />
</bean>
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager" />
</bean>
<bean id="mongoServer" class="org.usergrid.mongo.MongoServer"
init-method="startServer" destroy-method="stopServer" />
<bean id="usergridSystemMonitor" class="org.usergrid.system.UsergridSystemMonitor">
<constructor-arg value="${usergrid.version.build}" />
<constructor-arg ref="cassandraCluster" />
</bean>
<!-- override the security manager -->
<bean id="securityManager" class="org.usergrid.rest.security.shiro.RestSecurityManager">
<property name="cacheManager" ref="cacheManager" />
<property name="realm" ref="realm" />
</bean>
<bean id="cacheManager" class="org.apache.shiro.cache.MemoryConstrainedCacheManager" />
<!-- override the task executor -->
<bean id="taskExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="5" />
<property name="maxPoolSize" value="10" />
<property name="queueCapacity" value="25" />
</bean>
<bean id="binaryStore" class="org.usergrid.services.assets.data.LocalFileBinaryStore">
<property name="reposLocation" value="${usergrid.temp.files}"/>
</bean>
</beans>