当前位置: 首页>>代码示例>>Java>>正文


Java ContextLoader.getCurrentWebApplicationContext方法代码示例

本文整理汇总了Java中org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext方法的典型用法代码示例。如果您正苦于以下问题:Java ContextLoader.getCurrentWebApplicationContext方法的具体用法?Java ContextLoader.getCurrentWebApplicationContext怎么用?Java ContextLoader.getCurrentWebApplicationContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.context.ContextLoader的用法示例。


在下文中一共展示了ContextLoader.getCurrentWebApplicationContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loginNoSyncTenantBeta

import org.springframework.web.context.ContextLoader; //导入方法依赖的package包/类
@Test
public void loginNoSyncTenantBeta()
{
    AuthenticationUtil.setFullyAuthenticatedUser("admin");
    this.createAndEnableTenant("tenantbeta");

    final WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
    final PersonService personService = context.getBean("PersonService", PersonService.class);
    TenantUtil.runAsTenant(() -> {
        Assert.assertFalse("User [email protected] should not have been created yet", personService.personExists("[email protected]"));
        return null;
    }, "tenantbeta");
    AuthenticationUtil.clearCurrentSecurityContext();

    final AuthenticationService authenticationService = context.getBean("AuthenticationService", AuthenticationService.class);

    authenticationService.authenticate("[email protected]", "afaust".toCharArray());
    this.checkUserExistsAndState("[email protected]", "afaust", "", false);

    Assert.assertFalse("User [email protected] should not have been eagerly synchronized",
            personService.personExists("[email protected]"));
}
 
开发者ID:Acosix,项目名称:alfresco-mt-support,代码行数:23,代码来源:AuthenticationAndSynchronisationTests.java

示例2: processInjectionBasedOnCurrentContext

import org.springframework.web.context.ContextLoader; //导入方法依赖的package包/类
/**
 * Process {@code @Autowired} injection for the given target object,
 * based on the current web application context.
 * <p>Intended for use as a delegate.
 * @param target the target object to process
 * @see org.springframework.web.context.ContextLoader#getCurrentWebApplicationContext()
 */
public static void processInjectionBasedOnCurrentContext(Object target) {
	Assert.notNull(target, "Target object must not be null");
	WebApplicationContext cc = ContextLoader.getCurrentWebApplicationContext();
	if (cc != null) {
		AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
		bpp.setBeanFactory(cc.getAutowireCapableBeanFactory());
		bpp.processInjection(target);
	}
	else {
		if (logger.isDebugEnabled()) {
			logger.debug("Current WebApplicationContext is not available for processing of " +
					ClassUtils.getShortName(target.getClass()) + ": " +
					"Make sure this class gets constructed in a Spring web application. Proceeding without injection.");
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:SpringBeanAutowiringSupport.java

示例3: loginOnDemandSynchTenantAlpha

import org.springframework.web.context.ContextLoader; //导入方法依赖的package包/类
@Test
public void loginOnDemandSynchTenantAlpha()
{
    AuthenticationUtil.setFullyAuthenticatedUser("admin");
    this.createAndEnableTenant("tenantalpha");

    final WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
    final PersonService personService = context.getBean("PersonService", PersonService.class);
    TenantUtil.runAsTenant(() -> {
        Assert.assertFalse("User [email protected] should not have been synchronized yet",
                personService.personExists("[email protected]"));
        return null;
    }, "tenantalpha");
    AuthenticationUtil.clearCurrentSecurityContext();

    final AuthenticationService authenticationService = context.getBean("AuthenticationService", AuthenticationService.class);
    authenticationService.authenticate("[email protected]", "afaust".toCharArray());
    this.checkUserExistsAndState("[email protected]", "Axel", "Faust", false);
}
 
开发者ID:Acosix,项目名称:alfresco-mt-support,代码行数:20,代码来源:AuthenticationAndSynchronisationTests.java

示例4: createAndEnableTenant

import org.springframework.web.context.ContextLoader; //导入方法依赖的package包/类
protected void createAndEnableTenant(final String tenantName)
{
    final WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
    final TenantAdminService tenantAdminService = context.getBean("TenantAdminService", TenantAdminService.class);

    if (!tenantAdminService.existsTenant(tenantName))
    {
        tenantAdminService.createTenant(tenantName, "admin".toCharArray());
        // eager sync requires "normal" enabling - won't on creation by design
        tenantAdminService.disableTenant(tenantName);
    }
    if (!tenantAdminService.isEnabledTenant(tenantName))
    {
        tenantAdminService.enableTenant(tenantName);
    }
}
 
开发者ID:Acosix,项目名称:alfresco-mt-support,代码行数:17,代码来源:AuthenticationAndSynchronisationTests.java

示例5: contextInitialized

import org.springframework.web.context.ContextLoader; //导入方法依赖的package包/类
public void contextInitialized(ServletContextEvent contextEvent) {
	WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
	context.getBean(SysCacheService.class).flush();
	context.getBean(SysUserService.class).init();
	SysDicService sysDicService = context.getBean(SysDicService.class);
	sysDicService.getAllDic();
	super.contextInitialized(contextEvent);
}
 
开发者ID:guokezheng,项目名称:automat,代码行数:9,代码来源:SysServerListener.java

示例6: getJedis

import org.springframework.web.context.ContextLoader; //导入方法依赖的package包/类
private static ShardedJedis getJedis() {
    if (shardedJedisPool == null) {
        synchronized (EXPIRE) {
            if (shardedJedisPool == null) {
                WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
                shardedJedisPool = wac.getBean(ShardedJedisPool.class);
            }
        }
    }
    return shardedJedisPool.getResource();
}
 
开发者ID:tb544731152,项目名称:iBase4J,代码行数:12,代码来源:JedisTemplate.java

示例7: getRedis

import org.springframework.web.context.ContextLoader; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private RedisTemplate<Serializable, Serializable> getRedis() {
	if (redisTemplate == null) {
		synchronized (RedisHelper.class) {
			if (redisTemplate == null) {
				WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
				redisTemplate = (RedisTemplate<Serializable, Serializable>) wac.getBean("redisTemplate");
			}
		}
	}
	return redisTemplate;
}
 
开发者ID:tb544731152,项目名称:iBase4J,代码行数:13,代码来源:RedisHelper.java

示例8: getRedis

import org.springframework.web.context.ContextLoader; //导入方法依赖的package包/类
private RedissonClient getRedis() {
	if (redisTemplate == null) {
		synchronized (RedissonHelper.class) {
			if (redisTemplate == null) {
				WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
				redisTemplate = wac.getBean(Redisson.class);
			}
		}
	}
	return redisTemplate;
}
 
开发者ID:tb544731152,项目名称:iBase4J,代码行数:12,代码来源:RedissonHelper.java

示例9: contextInitialized

import org.springframework.web.context.ContextLoader; //导入方法依赖的package包/类
public void contextInitialized(ServletContextEvent contextEvent) {
	WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
	context.getBean(SysCacheService.class).flush();
	context.getBean(SysUserService.class).init();
	SysDicService sysDicService = context.getBean(SysDicService.class);
	sysDicService.getAllDic();
	MotanSwitcherUtil.setSwitcherValue(MotanConstants.REGISTRY_HEARTBEAT_SWITCHER, true);
	super.contextInitialized(contextEvent);
}
 
开发者ID:youngMen1,项目名称:JAVA-,代码行数:10,代码来源:SysServerListener.java

示例10: getWebApplicationContext

import org.springframework.web.context.ContextLoader; //导入方法依赖的package包/类
/**
 * Retrieve the Spring {@link WebApplicationContext} to use.
 * The default implementation returns the current {@link WebApplicationContext}
 * as registered for the thread context class loader.
 * @return the current WebApplicationContext (never {@code null})
 * @see ContextLoader#getCurrentWebApplicationContext()
 */
protected WebApplicationContext getWebApplicationContext() {
	WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
	if (wac == null) {
		throw new IllegalStateException("No WebApplicationContext registered for current thread - " +
				"consider overriding SpringWebConstraintValidatorFactory.getWebApplicationContext()");
	}
	return wac;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:SpringWebConstraintValidatorFactory.java

示例11: FtlView

import org.springframework.web.context.ContextLoader; //导入方法依赖的package包/类
public FtlView(String folder, String viewName) {
	try {
		ApplicationContext applicationContext = ContextLoader.getCurrentWebApplicationContext();
		this.setApplicationContext(applicationContext);
	}
	catch (Exception e) {
		// 兼容普通java环境
	}
	this.setUrl(viewName + ".ftl");
	this.folder = folder;
}
 
开发者ID:tanhaichao,项目名称:leopard,代码行数:12,代码来源:FtlView.java

示例12: findByParentId

import org.springframework.web.context.ContextLoader; //导入方法依赖的package包/类
public List<AuthMenu> findByParentId(long pid) {
    WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();

    AuthMenuService authMenuService = (AuthMenuService) wac.getBean(AuthMenuService.class);
    List<AuthMenu> list = authMenuService.findByParentId(pid);
    return list;
}
 
开发者ID:ThomasYangZi,项目名称:mblog,代码行数:8,代码来源:AuthMenuTool.java

示例13: loginStartupSynchDefaultTenant

import org.springframework.web.context.ContextLoader; //导入方法依赖的package包/类
@Test
public void loginStartupSynchDefaultTenant()
{
    // verifies users are eagerly synchronised on startup
    // synchronisation for missing people and and auto-creation of people is off for default tenant
    AuthenticationUtil.setFullyAuthenticatedUser("admin");
    this.checkUserExistsAndState("afaust", "Axel", "Faust", true);
    this.checkUserExistsAndState("mmustermann", "Max", "Mustermann", false);

    this.checkGroupsExistsAndMembers("Management", "Management", Arrays.asList("afaust"), Collections.emptyList(),
            Arrays.asList("afaust"), Collections.emptyList());
    this.checkGroupsExistsAndMembers("Client Development", "Client Development", Arrays.asList("mmustermann"), Collections.emptyList(),
            Arrays.asList("mmustermann"), Collections.emptyList());
    this.checkGroupsExistsAndMembers("Development", "Development", Collections.emptyList(), Arrays.asList("Client Development"),
            Arrays.asList("mmustermann"), Arrays.asList("Client Development"));
    this.checkGroupsExistsAndMembers("All Users", "All Users", Collections.emptyList(), Arrays.asList("Management", "Development"),
            Arrays.asList("afaust", "mmustermann"), Arrays.asList("Management", "Development", "Client Development"));
    AuthenticationUtil.clearCurrentSecurityContext();

    final WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
    final AuthenticationService authenticationService = context.getBean("AuthenticationService", AuthenticationService.class);

    authenticationService.authenticate("afaust", "afaust".toCharArray());
    authenticationService.authenticate("mmustermann", "mmustermann".toCharArray());

    this.thrown.expect(AuthenticationException.class);
    this.thrown.expectMessage("Failed to authenticate");
    authenticationService.authenticate("pmaier", "pmaier".toCharArray());
}
 
开发者ID:Acosix,项目名称:alfresco-mt-support,代码行数:30,代码来源:AuthenticationAndSynchronisationTests.java

示例14: checkUserExistsAndState

import org.springframework.web.context.ContextLoader; //导入方法依赖的package包/类
protected void checkUserExistsAndState(final String userName, final String firstName, final String lastName,
        final boolean avatarMustExist)
{
    final WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
    final PersonService personService = context.getBean("PersonService", PersonService.class);

    Assert.assertTrue("User should have been synchronised/created", personService.personExists(userName));
    final NodeRef personNodeRef = personService.getPerson(userName, false);
    final PersonInfo personInfo = personService.getPerson(personNodeRef);

    Assert.assertEquals("First name of user does not match expectation", firstName, personInfo.getFirstName());
    Assert.assertEquals("Last name of user does not match expectation", lastName, personInfo.getLastName());

    final NodeService nodeService = context.getBean("NodeService", NodeService.class);
    final ContentService contentService = context.getBean("ContentService", ContentService.class);

    final List<ChildAssociationRef> avatarAssocs = nodeService.getChildAssocs(personNodeRef, ContentModel.ASSOC_PREFERENCE_IMAGE,
            RegexQNamePattern.MATCH_ALL);
    Assert.assertEquals("No user thumbnail has been synchronised", avatarMustExist ? 1 : 0, avatarAssocs.size());
    if (avatarMustExist)
    {
        final NodeRef avatar = avatarAssocs.get(0).getChildRef();
        final ContentReader reader = contentService.getReader(avatar, ContentModel.PROP_CONTENT);

        Assert.assertNotNull("Avatar should have content", reader);
        Assert.assertTrue("Avatar should exist", reader.exists());
        Assert.assertNotEquals("Avatar should not be zero-byte", 0, reader.getSize());
        Assert.assertEquals("Avatar mimetype should have been image/jpeg", MimetypeMap.MIMETYPE_IMAGE_JPEG, reader.getMimetype());
    }
}
 
开发者ID:Acosix,项目名称:alfresco-mt-support,代码行数:31,代码来源:AuthenticationAndSynchronisationTests.java

示例15: checkGroupsExistsAndMembers

import org.springframework.web.context.ContextLoader; //导入方法依赖的package包/类
protected void checkGroupsExistsAndMembers(final String groupName, final String displayName, final Collection<String> directUserMembers,
        final Collection<String> directGroupMembers, final Collection<String> allUserMembers, final Collection<String> allGroupMembers)
{
    final WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
    final AuthorityService authorityService = context.getBean("AuthorityService", AuthorityService.class);

    final String groupFullName = AuthorityType.GROUP.getPrefixString() + groupName;
    Assert.assertTrue("Group should have been synchronised/created", authorityService.authorityExists(groupFullName));

    final String authorityDisplayName = authorityService.getAuthorityDisplayName(groupFullName);
    Assert.assertEquals("Display name of group does not match expectation", displayName, authorityDisplayName);

    final Set<String> immediateUsers = new HashSet<>(authorityService.getContainedAuthorities(AuthorityType.USER, groupFullName, true));
    final Set<String> immediateGroups = new HashSet<>(
            authorityService.getContainedAuthorities(AuthorityType.GROUP, groupFullName, true));

    final Set<String> expectedImmediateGroups = new HashSet<>();
    directGroupMembers.forEach((x) -> {
        expectedImmediateGroups.add(AuthorityType.GROUP.getPrefixString() + x);
    });
    final Set<String> expectedImmediateUsers = new HashSet<>(directUserMembers);

    Assert.assertEquals("Mismatch in groups as direct members of group", expectedImmediateGroups, immediateGroups);
    Assert.assertEquals("Mismatch in users as direct members of group", expectedImmediateUsers, immediateUsers);

    final Set<String> completeUsers = new HashSet<>(authorityService.getContainedAuthorities(AuthorityType.USER, groupFullName, false));
    final Set<String> completeGroups = new HashSet<>(
            authorityService.getContainedAuthorities(AuthorityType.GROUP, groupFullName, false));

    final Set<String> expectedCompleteGroups = new HashSet<>();
    allGroupMembers.forEach((x) -> {
        expectedCompleteGroups.add(AuthorityType.GROUP.getPrefixString() + x);
    });
    final Set<String> expectedCompleteUsers = new HashSet<>(allUserMembers);

    Assert.assertEquals("Mismatch in groups as direct or transitive members of group", expectedCompleteGroups, completeGroups);
    Assert.assertEquals("Mismatch in users as direct or transitive members of group", expectedCompleteUsers, completeUsers);
}
 
开发者ID:Acosix,项目名称:alfresco-mt-support,代码行数:39,代码来源:AuthenticationAndSynchronisationTests.java


注:本文中的org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。