本文整理了Java中org.springframework.web.context.WebApplicationContext.containsBean()
方法的一些代码示例,展示了WebApplicationContext.containsBean()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebApplicationContext.containsBean()
方法的具体详情如下:
包路径:org.springframework.web.context.WebApplicationContext
类名称:WebApplicationContext
方法名:containsBean
暂无
代码示例来源:origin: spring-projects/spring-framework
@Override
@Nullable
public Object getAttribute(String name) {
if ((this.explicitAttributes == null || !this.explicitAttributes.contains(name)) &&
(this.exposedContextBeanNames == null || this.exposedContextBeanNames.contains(name)) &&
this.webApplicationContext.containsBean(name)) {
return this.webApplicationContext.getBean(name);
}
else {
return super.getAttribute(name);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public boolean isReadOnly(ELContext elContext, @Nullable Object base, Object property) throws ELException {
if (base == null) {
String beanName = property.toString();
WebApplicationContext wac = getWebApplicationContext(elContext);
if (wac.containsBean(beanName)) {
return true;
}
}
return false;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
@Nullable
public Object getValue(ELContext elContext, @Nullable Object base, Object property) throws ELException {
if (base == null) {
String beanName = property.toString();
WebApplicationContext wac = getWebApplicationContext(elContext);
if (wac.containsBean(beanName)) {
elContext.setPropertyResolved(true);
return wac.getBean(beanName);
}
}
return null;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
@Nullable
public Class<?> getType(ELContext elContext, @Nullable Object base, Object property) throws ELException {
if (base == null) {
String beanName = property.toString();
WebApplicationContext wac = getWebApplicationContext(elContext);
if (wac.containsBean(beanName)) {
elContext.setPropertyResolved(true);
return wac.getType(beanName);
}
}
return null;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void setValue(ELContext elContext, @Nullable Object base, Object property, Object value) throws ELException {
if (base == null) {
String beanName = property.toString();
WebApplicationContext wac = getWebApplicationContext(elContext);
if (wac.containsBean(beanName)) {
if (value == wac.getBean(beanName)) {
// Setting the bean reference to the same value is alright - can simply be ignored...
elContext.setPropertyResolved(true);
}
else {
throw new PropertyNotWritableException(
"Variable '" + beanName + "' refers to a Spring bean which by definition is not writable");
}
}
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Look for a MultipartResolver bean in the root web application context.
* Supports a "multipartResolverBeanName" filter init param; the default
* bean name is "filterMultipartResolver".
* <p>This can be overridden to use a custom MultipartResolver instance,
* for example if not using a Spring web application context.
* @return the MultipartResolver instance
*/
protected MultipartResolver lookupMultipartResolver() {
WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
String beanName = getMultipartResolverBeanName();
if (wac != null && wac.containsBean(beanName)) {
if (logger.isDebugEnabled()) {
logger.debug("Using MultipartResolver '" + beanName + "' for MultipartFilter");
}
return wac.getBean(beanName, MultipartResolver.class);
}
else {
return this.defaultMultipartResolver;
}
}
代码示例来源:origin: rest-assured/rest-assured
public RequestPostProcessor beforeMockMvcCreated(ConfigurableMockMvcBuilder<?> builder, WebApplicationContext context) {
if (!context.containsBean(SPRING_SECURITY_FILTER_CHAIN)) {
return null;
}
return configurer.beforeMockMvcCreated(builder, context);
}
}
代码示例来源:origin: org.springframework/spring-web
@Override
public boolean isReadOnly(ELContext elContext, @Nullable Object base, Object property) throws ELException {
if (base == null) {
String beanName = property.toString();
WebApplicationContext wac = getWebApplicationContext(elContext);
if (wac.containsBean(beanName)) {
return true;
}
}
return false;
}
代码示例来源:origin: org.springframework/spring-web
@Override
@Nullable
public Object getAttribute(String name) {
if ((this.explicitAttributes == null || !this.explicitAttributes.contains(name)) &&
(this.exposedContextBeanNames == null || this.exposedContextBeanNames.contains(name)) &&
this.webApplicationContext.containsBean(name)) {
return this.webApplicationContext.getBean(name);
}
else {
return super.getAttribute(name);
}
}
代码示例来源:origin: org.springframework/spring-web
@Override
@Nullable
public Object getValue(ELContext elContext, @Nullable Object base, Object property) throws ELException {
if (base == null) {
String beanName = property.toString();
WebApplicationContext wac = getWebApplicationContext(elContext);
if (wac.containsBean(beanName)) {
elContext.setPropertyResolved(true);
return wac.getBean(beanName);
}
}
return null;
}
代码示例来源:origin: spring-projects/spring-framework
logger.trace("Attempting to resolve property '" + beanName + "' in root WebApplicationContext");
if (wac.containsBean(beanName)) {
if (logger.isDebugEnabled()) {
logger.debug("Successfully resolved property '" + beanName + "' in root WebApplicationContext");
代码示例来源:origin: spring-projects/spring-framework
if (wac.containsBean(beanName)) {
T endpoint = wac.getBean(beanName, endpointClass);
if (logger.isTraceEnabled()) {
if (ann != null && wac.containsBean(ann.value())) {
T endpoint = wac.getBean(ann.value(), endpointClass);
if (logger.isTraceEnabled()) {
代码示例来源:origin: spring-projects/spring-framework
/**
* Look up the EntityManagerFactory that this filter should use.
* <p>The default implementation looks for a bean with the specified name
* in Spring's root application context.
* @return the EntityManagerFactory to use
* @see #getEntityManagerFactoryBeanName
*/
protected EntityManagerFactory lookupEntityManagerFactory() {
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
String emfBeanName = getEntityManagerFactoryBeanName();
String puName = getPersistenceUnitName();
if (StringUtils.hasLength(emfBeanName)) {
return wac.getBean(emfBeanName, EntityManagerFactory.class);
}
else if (!StringUtils.hasLength(puName) && wac.containsBean(DEFAULT_ENTITY_MANAGER_FACTORY_BEAN_NAME)) {
return wac.getBean(DEFAULT_ENTITY_MANAGER_FACTORY_BEAN_NAME, EntityManagerFactory.class);
}
else {
// Includes fallback search for single EntityManagerFactory bean by type.
return EntityManagerFactoryUtils.findEntityManagerFactory(wac, puName);
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Find the registered {@link RequestDataValueProcessor}, if any, and allow
* it to update the redirect target URL.
* @param targetUrl the given redirect URL
* @return the updated URL or the same as URL as the one passed in
*/
protected String updateTargetUrl(String targetUrl, Map<String, Object> model,
HttpServletRequest request, HttpServletResponse response) {
WebApplicationContext wac = getWebApplicationContext();
if (wac == null) {
wac = RequestContextUtils.findWebApplicationContext(request, getServletContext());
}
if (wac != null && wac.containsBean(RequestContextUtils.REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME)) {
RequestDataValueProcessor processor = wac.getBean(
RequestContextUtils.REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME, RequestDataValueProcessor.class);
return processor.processUrl(request, targetUrl);
}
return targetUrl;
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void register() throws ServletException {
initializer.onStartup(servletContext);
assertEquals(1, servlets.size());
assertNotNull(servlets.get(SERVLET_NAME));
DispatcherServlet servlet = (DispatcherServlet) servlets.get(SERVLET_NAME);
assertEquals(MyDispatcherServlet.class, servlet.getClass());
WebApplicationContext servletContext = servlet.getWebApplicationContext();
assertTrue(servletContext.containsBean("bean"));
assertTrue(servletContext.getBean("bean") instanceof MyBean);
assertEquals(1, registrations.size());
assertNotNull(registrations.get(SERVLET_NAME));
MockServletRegistration registration = registrations.get(SERVLET_NAME);
assertEquals(Collections.singleton(SERVLET_MAPPING), registration.getMappings());
assertEquals(1, registration.getLoadOnStartup());
assertEquals(ROLE_NAME, registration.getRunAsRole());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testFrameworkServletWithCustomLocation() throws Exception {
DispatcherServlet servlet = new DispatcherServlet();
servlet.setContextConfigLocation("/org/springframework/web/context/WEB-INF/testNamespace.xml "
+ "/org/springframework/web/context/WEB-INF/context-addition.xml");
servlet.init(new MockServletConfig(new MockServletContext(""), "test"));
assertTrue(servlet.getWebApplicationContext().containsBean("kerry"));
assertTrue(servlet.getWebApplicationContext().containsBean("kerryX"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testContextLoaderListenerWithDefaultContext() {
MockServletContext sc = new MockServletContext("");
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
"/org/springframework/web/context/WEB-INF/applicationContext.xml " +
"/org/springframework/web/context/WEB-INF/context-addition.xml");
ServletContextListener listener = new ContextLoaderListener();
ServletContextEvent event = new ServletContextEvent(sc);
listener.contextInitialized(event);
String contextAttr = WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE;
WebApplicationContext context = (WebApplicationContext) sc.getAttribute(contextAttr);
assertTrue("Correct WebApplicationContext exposed in ServletContext", context instanceof XmlWebApplicationContext);
assertTrue(WebApplicationContextUtils.getRequiredWebApplicationContext(sc) instanceof XmlWebApplicationContext);
LifecycleBean lb = (LifecycleBean) context.getBean("lifecycle");
assertTrue("Has father", context.containsBean("father"));
assertTrue("Has rod", context.containsBean("rod"));
assertTrue("Has kerry", context.containsBean("kerry"));
assertTrue("Not destroyed", !lb.isDestroyed());
assertFalse(context.containsBean("beans1.bean1"));
assertFalse(context.containsBean("beans1.bean2"));
listener.contextDestroyed(event);
assertTrue("Destroyed", lb.isDestroyed());
assertNull(sc.getAttribute(contextAttr));
assertNull(WebApplicationContextUtils.getWebApplicationContext(sc));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void register() throws ServletException {
initializer.onStartup(servletContext);
assertTrue(eventListener instanceof ContextLoaderListener);
ContextLoaderListener cll = (ContextLoaderListener) eventListener;
cll.contextInitialized(new ServletContextEvent(servletContext));
WebApplicationContext applicationContext = WebApplicationContextUtils
.getRequiredWebApplicationContext(servletContext);
assertTrue(applicationContext.containsBean(BEAN_NAME));
assertTrue(applicationContext.getBean(BEAN_NAME) instanceof MyBean);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void register() throws ServletException {
initializer.onStartup(servletContext);
assertEquals(1, servlets.size());
assertNotNull(servlets.get(SERVLET_NAME));
DispatcherServlet servlet = (DispatcherServlet) servlets.get(SERVLET_NAME);
WebApplicationContext wac = servlet.getWebApplicationContext();
((AnnotationConfigWebApplicationContext) wac).refresh();
assertTrue(wac.containsBean("bean"));
assertTrue(wac.getBean("bean") instanceof MyBean);
assertEquals(1, servletRegistrations.size());
assertNotNull(servletRegistrations.get(SERVLET_NAME));
MockServletRegistration servletRegistration = servletRegistrations.get(SERVLET_NAME);
assertEquals(Collections.singleton(SERVLET_MAPPING), servletRegistration.getMappings());
assertEquals(1, servletRegistration.getLoadOnStartup());
assertEquals(ROLE_NAME, servletRegistration.getRunAsRole());
assertTrue(servletRegistration.isAsyncSupported());
assertEquals(4, filterRegistrations.size());
assertNotNull(filterRegistrations.get("hiddenHttpMethodFilter"));
assertNotNull(filterRegistrations.get("delegatingFilterProxy"));
assertNotNull(filterRegistrations.get("delegatingFilterProxy#0"));
assertNotNull(filterRegistrations.get("delegatingFilterProxy#1"));
for (MockFilterRegistration filterRegistration : filterRegistrations.values()) {
assertTrue(filterRegistration.isAsyncSupported());
EnumSet<DispatcherType> enumSet = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD,
DispatcherType.INCLUDE, DispatcherType.ASYNC);
assertEquals(enumSet, filterRegistration.getMappings().get(SERVLET_NAME));
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void rootContextOnly() throws ServletException {
initializer = new MyAnnotationConfigDispatcherServletInitializer() {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[] {MyConfiguration.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
return null;
}
};
initializer.onStartup(servletContext);
DispatcherServlet servlet = (DispatcherServlet) servlets.get(SERVLET_NAME);
servlet.init(new MockServletConfig(this.servletContext));
WebApplicationContext wac = servlet.getWebApplicationContext();
((AnnotationConfigWebApplicationContext) wac).refresh();
assertTrue(wac.containsBean("bean"));
assertTrue(wac.getBean("bean") instanceof MyBean);
}
内容来源于网络,如有侵权,请联系作者删除!