insane
Apr 23rd, 2007, 04:12 AM
Hi,
I have web application that uses some configuration file that should be loaded from some location when there is proper request for it. This request contains this url (it's an address to FTP server) and all necessary data like user, password etc. I have defined a map that contains some keys and previously loaded configurations (each of these keys was previously delivered in the request). And when there is a request for some configuration (so, there is one of these keys in the request) ConfigurationLoader should fetch proper configuration from the map.
I hope so far everything is clear :-).
So, how it's made:
We have an EntryController that searches the request for all data necessary to connect to FTP server to get configuration file from. If all data is found and this data is correct, downloaded configuration file is put in the map at the key passed also in request. Configuration of this part looks like this:
<bean id="entryController" class="com.iim.web.spring.controllers.EntryController">
<property name="configurations">
<ref bean="configurations" />
</property>
</bean>
where configurations is:
<bean id="configurations" class="java.util.HashMap" />
Ok. Another part is ConfigurationFactory that is responsible for fetching proper configuration from the map using the given key:
<bean id="configurationFactory" class="com.iim.imagemanager.ConfigurationFactory" />
and it's code:
public class ConfigurationFactory {
private Map<String, Configuration> configurations;
public Configuration fetchConfiguration() {
String id = ((WebRequest) RequestContextHolder.currentRequestAttributes()).g etParameter("id");
if (id != null && id.length() > 0) {
Configuration configuration = configurations.get(id);
if (configuration != null)
return configuration;
}
return null;
}
}
And at last, configuration:
<bean id="configuration" factory-bean="configurationFactory" factory-method="fetchConfiguration" scope="session">
<aop:scoped-proxy />
</bean>
So... As you can see, I'm trying to use scoped proxy to inject proper configuration to all beans that needs it. But I get a bunch of errors when I try to restart this application (I paste only a small part of them, if whole stack is needed I can paste it but it's quite long):
Caused by:
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'scopedTarget.configuration': Scope 'session' is not active for the current thread; consider defining a scoped proxy for
this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web
request? If you are actually operating within a web request and still receive this message,your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListen
er or RequestContextFilter to expose the current request.
Caused by:
java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request? If you are actually operating within a web request and still receive
this message,your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
Well, I set session scope, I used aop:scoped-proxy... I don't know what is still wrong. Any ideas?
I have web application that uses some configuration file that should be loaded from some location when there is proper request for it. This request contains this url (it's an address to FTP server) and all necessary data like user, password etc. I have defined a map that contains some keys and previously loaded configurations (each of these keys was previously delivered in the request). And when there is a request for some configuration (so, there is one of these keys in the request) ConfigurationLoader should fetch proper configuration from the map.
I hope so far everything is clear :-).
So, how it's made:
We have an EntryController that searches the request for all data necessary to connect to FTP server to get configuration file from. If all data is found and this data is correct, downloaded configuration file is put in the map at the key passed also in request. Configuration of this part looks like this:
<bean id="entryController" class="com.iim.web.spring.controllers.EntryController">
<property name="configurations">
<ref bean="configurations" />
</property>
</bean>
where configurations is:
<bean id="configurations" class="java.util.HashMap" />
Ok. Another part is ConfigurationFactory that is responsible for fetching proper configuration from the map using the given key:
<bean id="configurationFactory" class="com.iim.imagemanager.ConfigurationFactory" />
and it's code:
public class ConfigurationFactory {
private Map<String, Configuration> configurations;
public Configuration fetchConfiguration() {
String id = ((WebRequest) RequestContextHolder.currentRequestAttributes()).g etParameter("id");
if (id != null && id.length() > 0) {
Configuration configuration = configurations.get(id);
if (configuration != null)
return configuration;
}
return null;
}
}
And at last, configuration:
<bean id="configuration" factory-bean="configurationFactory" factory-method="fetchConfiguration" scope="session">
<aop:scoped-proxy />
</bean>
So... As you can see, I'm trying to use scoped proxy to inject proper configuration to all beans that needs it. But I get a bunch of errors when I try to restart this application (I paste only a small part of them, if whole stack is needed I can paste it but it's quite long):
Caused by:
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'scopedTarget.configuration': Scope 'session' is not active for the current thread; consider defining a scoped proxy for
this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web
request? If you are actually operating within a web request and still receive this message,your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListen
er or RequestContextFilter to expose the current request.
Caused by:
java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request? If you are actually operating within a web request and still receive
this message,your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
Well, I set session scope, I used aop:scoped-proxy... I don't know what is still wrong. Any ideas?