Skip to content

Instantly share code, notes, and snippets.

@ruanjf
Last active December 29, 2015 14:49
Show Gist options
  • Save ruanjf/7686923 to your computer and use it in GitHub Desktop.
Save ruanjf/7686923 to your computer and use it in GitHub Desktop.
java web工程 添加WebLogic支持 详细请查看0-WebLogic-Support.md

java web工程 添加WebLogic支持

  • web.xml 由于在weblogic中通过JS异步请求直接读取XML文件,发现在IE中无法通过request.responseXML获取,因为它不认为是XML,主要是因为没有设置contentType="text/xml",因此需要在web.xml中添加MIME映射。

  • weblogic.xml(与web.xml同级) 由于jar包与WebLogic自带的冲突,需设置项目jar优先。

  • ClassesFind.java 在WebLogic中普通的classloader无法获取class改用spring 2.5提供的方式查找

package com.runjf.utils;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.core.type.filter.AssignableTypeFilter;
import org.springframework.util.ClassUtils;
/**
* 查找class
*
* @author rjf
* @since 2013-11-28
*
*/
public class ClassesFind {
/**
* 加载class,采用Spring 2.5提供的{@link ClassPathScanningCandidateComponentProvider}来获取
*
* @param basePackage 包路径 默认根路径开始查找
* @param include 包含的类型
* @return 不存在返回空的set
*/
public Set<Class<?>> findByPackage(String basePackage, Class<?>... include) {
if (include != null && include.length > 0) {
ClassPathScanningCandidateComponentProvider cpsccp = new ClassPathScanningCandidateComponentProvider(false);
// 指定包含的类型
for (Class<?> cls : include) {
cpsccp.addIncludeFilter(new AssignableTypeFilter(cls));
}
// 查找包并制定包路径
Set<BeanDefinition> confs = cpsccp.findCandidateComponents(basePackage == null || basePackage.trim().isEmpty() ? "/" : basePackage);
if (confs != null && !confs.isEmpty()) {
ClassLoader cl = ClassUtils.getDefaultClassLoader();
if (cl != null) {
Set<Class<?>> rs = new HashSet<Class<?>>(confs.size());
for (BeanDefinition beanDefinition : confs) {
if (beanDefinition != null) {
try {
rs.add(cl.loadClass(beanDefinition.getBeanClassName()));
} catch (ClassNotFoundException e) {
System.out.println("Class.forName error:"+beanDefinition.getBeanClassName());
}
}
}
return rs;
}
}
}
return Collections.emptySet();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
...
<mime-mapping>
<!-- weblogic support -->
<extension>xml</extension>
<mime-type>text/xml</mime-type>
</mime-mapping>
...
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app>
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
<!--
<prefer-web-inf-classes>false</prefer-web-inf-classes>
<prefer-application-packages>
<package-name>antlr.*</package-name>
</prefer-application-packages>
-->
<show-archived-real-path-enabled>true</show-archived-real-path-enabled>
</container-descriptor>
</weblogic-web-app>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment