本文整理匯總了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]"));
}
示例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.");
}
}
}
示例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);
}
示例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);
}
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
示例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());
}
}
示例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);
}