解决在JBoss 下不能找到 Action 问题

网友投稿 634 2022-10-29

解决在JBoss 下不能找到 Action 问题

解决在JBoss 下不能找到 Action 问题

import java-.MalformedURLException; import java-.URL; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts2.convention.PackageBasedActionConfigBuilder; import com.opensymphony.xwork2.ObjectFactory; import com.opensymphony.xwork2.config.Configuration; import com.opensymphony.xwork2.inject.Container; import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.util.finder.ClassFinder; import com.opensymphony.xwork2.util.finder.Test; /** * * 解决在JBoss 下不能找到 Action 问题 * */ public class MyActionConfigBuilder extends PackageBasedActionConfigBuilder { private static Log log = LogFactory.getLog(MyActionConfigBuilder.class); private static final String BASE_FILE = "applicationContext.xml"; private String[] actionPackages; private String[] packageLocators; public static String classPath=""; /** * * @param configuration * @param container * @param objectFactory * @param redirectToSlash * @param defaultParentPackage */ @Inject public MyActionConfigBuilder( Configuration configuration, Container container, ObjectFactory objectFactory, @Inject("struts.convention.redirect.to.slash") String redirectToSlash, @Inject("struts.convention.default.parent.package") String defaultParentPackage) { super( configuration, container, objectFactory, redirectToSlash, defaultParentPackage ); } /** * * @param actionPackages * (Optional) An optional list of action packages that this * should create * * configuration for. * */ @Inject(value = "struts.convention.action.packages", required = false) public void setActionPackages(String actionPackages) { super.setActionPackages(actionPackages); if ( !"".equals( actionPackages.trim() ) ) { this.actionPackages = actionPackages.split( "\s*[,]\s*" ); } } /** * * @param packageLocators * (Optional) A list of names used to find action packages. * */ @Inject(value = "struts.convention.package.locators", required = false) public void setPackageLocators(String packageLocators) { super.setPackageLocators(packageLocators); this.packageLocators = packageLocators.split("\s*[,]\s*"); } @Override @SuppressWarnings("unchecked") protected Set findActions() { Set classes = new HashSet(); try { // ClassFinder finder = new ClassFinder(getClassLoaderForFinder(), buildUrls(), true); ClassFinder finder = new ClassFinder( getClassLoaderInterface(), buildUrls(), true); if (actionPackages != null) { for (String packageName : actionPackages) { Test test = getPackageFinderTest(packageName); classes.addAll(finder.findClasses(test)); } } // package locators if (packageLocators != null) { for (String packageLocator : packageLocators) { Test test = getPackageLocatorTest(packageLocator); classes.addAll(finder.findClasses(test)); } } } catch (Exception ex) { if (log.isErrorEnabled()) { log.error("Unable to scan named packages", ex); } } return classes; } private List buildUrls() throws MalformedURLException { List urls = new ArrayList(); URL classesUrl = getClassLoader().getResource( BASE_FILE ); if (classesUrl == null) { throw new IllegalStateException( "File " + BASE_FILE + " was not found. The folder WEB-INF/classes discovery base on file classes/" + BASE_FILE + "."); } String baseFilePath = classesUrl.getFile(); URL url = new URL( "file", "", baseFilePath.substring( 0, baseFilePath.indexOf( BASE_FILE ) ) ); if (log.isInfoEnabled()) { classPath=url.getFile(); log.info("Struts2 ActionConfigBuilder, classes directory: " + classPath); } urls.add(url); return urls; } /*private ClassLoader getClassLoader() { return Thread.currentThread().getContextClassLoader(); }*/ }

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:ko - Google开源的工具用于在Kubernetes上构建和部署Go应用程序
下一篇:小程序app开发公司(小程序app开发公司排名)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~