in plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java [63:143]
public StrutsSpringObjectFactory(
@Inject(value=StrutsConstants.STRUTS_OBJECTFACTORY_SPRING_AUTOWIRE,required=false) String autoWire,
@Inject(value=StrutsConstants.STRUTS_OBJECTFACTORY_SPRING_AUTOWIRE_ALWAYS_RESPECT,required=false) String alwaysAutoWire,
@Inject(value=StrutsConstants.STRUTS_OBJECTFACTORY_SPRING_USE_CLASS_CACHE,required=false) String useClassCacheStr,
@Inject(value=StrutsConstants.STRUTS_OBJECTFACTORY_SPRING_ENABLE_AOP_SUPPORT,required=false) String enableAopSupport,
@Inject ServletContext servletContext,
@Inject(StrutsConstants.STRUTS_DEVMODE) String devMode,
@Inject Container container) {
boolean useClassCache = BooleanUtils.toBoolean(useClassCacheStr);
LOG.info("Initializing Struts-Spring integration...");
Object rootWebApplicationContext = servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
if(rootWebApplicationContext instanceof RuntimeException){
RuntimeException runtimeException = (RuntimeException)rootWebApplicationContext;
LOG.fatal(runtimeException.getMessage());
return;
}
ApplicationContext appContext = (ApplicationContext) rootWebApplicationContext;
if (appContext == null) {
// uh oh! looks like the lifecycle listener wasn't installed. Let's inform the user
String message = "********** FATAL ERROR STARTING UP STRUTS-SPRING INTEGRATION **********\n" +
"Looks like the Spring listener was not configured for your web app! \n" +
"Nothing will work until WebApplicationContextUtils returns a valid ApplicationContext.\n" +
"You might need to add the following to web.xml: \n" +
" <listener>\n" +
" <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>\n" +
" </listener>";
LOG.fatal(message);
return;
}
String watchList = container.getInstance(String.class, SpringConstants.STRUTS_OBJECTFACTORY_SPRING_CLASS_RELOADING_WATCH_LIST);
String acceptClasses = container.getInstance(String.class, SpringConstants.STRUTS_OBJECTFACTORY_SPRING_CLASS_RELOADING_ACCEPT_CLASSES);
String reloadConfig = container.getInstance(String.class, SpringConstants.STRUTS_OBJECTFACTORY_SPRING_CLASS_RELOADING_RELOAD_CONFIG);
if ("true".equals(devMode)
&& StringUtils.isNotBlank(watchList)
&& appContext instanceof ClassReloadingXMLWebApplicationContext) {
//prevent class caching
useClassCache = false;
try (ClassReloadingXMLWebApplicationContext reloadingContext = (ClassReloadingXMLWebApplicationContext) appContext) {
reloadingContext.setupReloading(watchList.split(","), acceptClasses, servletContext,
"true".equals(reloadConfig));
LOG.info("Class reloading is enabled. Make sure this is not used on a production environment!\n{}",
watchList);
setClassLoader(reloadingContext.getReloadingClassLoader());
// we need to reload the context, so our isntance of the factory is picked up
reloadingContext.refresh();
}
}
this.setApplicationContext(appContext);
int type = AutowireCapableBeanFactory.AUTOWIRE_BY_NAME; // default
if ("name".equals(autoWire)) {
type = AutowireCapableBeanFactory.AUTOWIRE_BY_NAME;
} else if ("type".equals(autoWire)) {
type = AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE;
} else if ("auto".equals(autoWire)) {
type = AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT;
} else if ("constructor".equals(autoWire)) {
type = AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR;
} else if ("no".equals(autoWire)) {
type = AutowireCapableBeanFactory.AUTOWIRE_NO;
}
this.setAutowireStrategy(type);
this.setUseClassCache(useClassCache);
this.setAlwaysRespectAutowireStrategy(BooleanUtils.toBoolean(alwaysAutoWire));
this.setEnableAopSupport(enableAopSupport);
LOG.info("... initialized Struts-Spring integration successfully");
}