Skip to content

Commit

Permalink
代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
smthing committed Aug 12, 2024
1 parent a44c661 commit f51c941
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class AnnotationsLoader {

private final Map<Class, List<String>> annotations = new HashMap<>();

private final Map<String, ServletInfo> servlets = new HashMap<>();
private final List<ServletInfo> servlets = new ArrayList<>();
private final List<ServletMappingInfo> servletMappings = new ArrayList<>();
private final List<FilterInfo> filters = new ArrayList<>();
private final List<FilterMappingInfo> filterMappings = new ArrayList<>();
Expand Down Expand Up @@ -142,14 +142,22 @@ public Map<ServletContainerInitializer, Set<Class<?>>> getInitializerClassMap()
return initializerClassMap;
}

public Map<String, ServletInfo> getServlets() {
public List<ServletInfo> getServlets() {
return servlets;
}

public List<FilterInfo> getFilters() {
return filters;
}

public List<FilterMappingInfo> getFilterMappings() {
return filterMappings;
}

public List<ServletMappingInfo> getServletMappings() {
return servletMappings;
}

public List<String> getAnnotations(Class clazz) {
List<String> classes = annotations.get(clazz);
return CollectionUtils.isEmpty(classes) ? Collections.emptyList() : classes;
Expand Down Expand Up @@ -269,7 +277,7 @@ private void checkAnnotation(JavaClass javaClass, Map<String, JavaClassCacheEntr
// if (servletSecurity != null) {
// servletSecurity.value()
// }
servlets.put(name, servletInfo);
servlets.add(servletInfo);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,17 @@ private void initContainer(DeploymentInfo deploymentInfo) throws ServletExceptio
System.out.println(listener);
servletContext.addListener(listener);
});
deploymentInfo.getHandlesTypesLoader().getServlets().values().forEach(servletInfo -> {
deploymentInfo.getHandlesTypesLoader().getServlets().forEach(servletInfo -> {
ServletInfo webXmlInfo = deploymentInfo.getServlets().get(servletInfo.getServletName());
if (webXmlInfo != null) {
servletInfo.getInitParams().forEach(webXmlInfo::addInitParam);
} else {
deploymentInfo.addServlet(servletInfo);
}
});
deploymentInfo.getHandlesTypesLoader().getFilters().forEach(filterInfo -> {
deploymentInfo.addFilter(filterInfo);
});
deploymentInfo.getHandlesTypesLoader().getServletMappings().forEach(deploymentInfo::addServletMapping);
deploymentInfo.getHandlesTypesLoader().getFilters().forEach(deploymentInfo::addFilter);
deploymentInfo.getHandlesTypesLoader().getFilterMappings().forEach(deploymentInfo::addFilterMapping);
deploymentInfo.getHandlesTypesLoader().clear();
deploymentInfo.setHandlesTypesLoader(null);
// System.out.println("scanHandleTypes use :" + (System.currentTimeMillis() - start));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ public void mergeTo(WebAppInfo webAppInfo) {
}
});
webAppInfo.getFilterMappingInfos().addAll(getFilterMappingInfos());
webAppInfo.getServletMappings().addAll(getServletMappings());
//具有相同<servlet-name>的<servlet-mapping>元素可以添加到多个 web-fragment。在 web.xml 中
//指定的<servlet-mapping>覆盖在 web-fragment 中指定的同名的<servlet-name>的<servlet-mapping>
getServletMappings().forEach(fragmentMapping -> {
if (webAppInfo.getServletMappings().stream().noneMatch(mapping -> mapping.getServletName().equals(fragmentMapping.getServletName()))) {
webAppInfo.getServletMappings().add(fragmentMapping);
}
});
webAppInfo.getListeners().addAll(getListeners());
webAppInfo.getWelcomeFileList().addAll(getWelcomeFileList());
webAppInfo.getErrorPages().addAll(getErrorPages());
Expand Down

0 comments on commit f51c941

Please sign in to comment.