本文整理汇总了Java中org.springframework.context.ApplicationContext类的典型用法代码示例。如果您正苦于以下问题:Java ApplicationContext类的具体用法?Java ApplicationContext怎么用?Java ApplicationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ApplicationContext类属于org.springframework.context包,在下文中一共展示了ApplicationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setApplicationContext
import org.springframework.context.ApplicationContext; //导入依赖的package包/类
@Override
public final void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
try {
logger.info("Initializing {} root application context", contextInitializerName);
initializeRootApplicationContext();
logger.info("Initialized {} root application context successfully", contextInitializerName);
logger.info("Initializing {} servlet application context", contextInitializerName);
initializeServletApplicationContext();
logger.info("Initialized {} servlet application context successfully", contextInitializerName);
} catch (final Exception e) {
logger.error(e.getMessage(), e);
}
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:17,代码来源:AbstractServletContextInitializer.java
示例2: jettyServer
import org.springframework.context.ApplicationContext; //导入依赖的package包/类
@Bean
public Server jettyServer(ApplicationContext context) throws Exception {
HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
Servlet servlet = new JettyHttpHandlerAdapter(handler);
Server server = new Server();
ServletContextHandler contextHandler = new ServletContextHandler(server, "");
contextHandler.addServlet(new ServletHolder(servlet), "/");
contextHandler.start();
ServerConnector connector = new ServerConnector(server);
connector.setHost("localhost");
connector.setPort(port);
server.addConnector(connector);
return server;
}
示例3: Test4
import org.springframework.context.ApplicationContext; //导入依赖的package包/类
@Test
public void Test4(){
ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");//��ʼ������
BuildingDealDao buildingDealDao = (BuildingDealDao) ac.getBean("buildingDealDao");
BuildingDeal u = new BuildingDeal();
u.setAgentId(2);
u.setBuildingDealPerPrice(100);
u.setBuildingDealTime(new Date());
u.setBuildingDealTotalPrice(100);
u.setBuildingId(1);
u.setBuildingLayout("111��һ��");
u.setUserId(1);
u.setBuildingDealId(1);
buildingDealDao.deleteBuildingDeal(u);
System.out.println(u.getBuildingLayout());
}
示例4: mockApplicationContext
import org.springframework.context.ApplicationContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Before
public void mockApplicationContext() {
final ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class);
SpringUtils.setSharedApplicationContext(applicationContext);
mockLdapResource = Mockito.mock(UserOrgResource.class);
final UserFullLdapTask mockTask = new UserFullLdapTask();
mockTask.resource = mockLdapResource;
mockTask.securityHelper = securityHelper;
final UserAtomicLdapTask mockTaskUpdate = new UserAtomicLdapTask();
mockTaskUpdate.resource = mockLdapResource;
mockTaskUpdate.securityHelper = securityHelper;
Mockito.when(applicationContext.getBean(SessionSettings.class)).thenReturn(new SessionSettings());
Mockito.when(applicationContext.getBean((Class<?>) ArgumentMatchers.any(Class.class))).thenAnswer((Answer<Object>) invocation -> {
final Class<?> requiredType = (Class<Object>) invocation.getArguments()[0];
if (requiredType == UserFullLdapTask.class) {
return mockTask;
}
if (requiredType == UserAtomicLdapTask.class) {
return mockTaskUpdate;
}
return UserBatchLdapResourceTest.super.applicationContext.getBean(requiredType);
});
mockTaskUpdate.jaxrsFactory = ServerProviderFactory.createInstance(null);
}
示例5: after
import org.springframework.context.ApplicationContext; //导入依赖的package包/类
@Override protected void after()
{
// Set up required services
ApplicationContext ctxt = getApplicationContext();
final RetryingTransactionHelper transactionHelper = (RetryingTransactionHelper) ctxt.getBean("retryingTransactionHelper");
transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override public Void execute() throws Throwable
{
for (Map.Entry<String, NodeRef> entry : usersPersons.entrySet())
{
deletePerson(entry.getKey());
}
return null;
}
});
}
示例6: main
import org.springframework.context.ApplicationContext; //导入依赖的package包/类
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(LearnspringdiApplication.class, args);
//Always the bean name will be equivalent to the class name (but starts with lowercase)
FirstController controller = (FirstController) ctx.getBean("firstController");
System.out.println(controller.sayHello());
System.out.println(ctx.getBean(PropertyInjectController.class).sayHello());
System.out.println(ctx.getBean(SetterInjectController.class).sayHello());
System.out.println(ctx.getBean(ConstructorInjectController.class).sayHello());
TestDataSource testDataSource = (TestDataSource) ctx.getBean(TestDataSource.class);
System.out.println("Reading value from external Property File :"+ testDataSource.getDbUrl());
TestEnvProp testEnvProp = (TestEnvProp) ctx.getBean(TestEnvProp.class);
System.out.println("Accessed System value through Spring Environmet Variable "+testEnvProp.getSystemUserName());
System.out.println("Accessed System value directly via Spring @Value Annotation :"+testEnvProp.JAVA_VERSION);
TestJmsBroker testJmsBroker = (TestJmsBroker) ctx.getBean(TestJmsBroker.class);
System.out.println("Accessed multiple property file values using @PropertySources :"+testJmsBroker.getJmsUrl());
}
示例7: setApplicationContext
import org.springframework.context.ApplicationContext; //导入依赖的package包/类
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
try {
repository = repositoryBuilder.getRepository();
SimpleCredentials cred = new SimpleCredentials("admin", "admin".toCharArray());
cred.setAttribute("AutoRefresh", true);
session = repository.login(cred, null);
versionManager = session.getWorkspace().getVersionManager();
lockManager=session.getWorkspace().getLockManager();
Collection<RepositoryInteceptor> repositoryInteceptors=applicationContext.getBeansOfType(RepositoryInteceptor.class).values();
if(repositoryInteceptors.size()==0){
repositoryInteceptor=new DefaultRepositoryInteceptor();
}else{
repositoryInteceptor=repositoryInteceptors.iterator().next();
}
} catch (Exception ex) {
throw new RuleException(ex);
}
}
示例8: release
import org.springframework.context.ApplicationContext; //导入依赖的package包/类
@Override
public void release() {
if (this.applicationContext != null) {
ApplicationContext savedCtx;
// We don't actually guarantee thread-safety, but it's not a lot of extra work.
synchronized (this) {
savedCtx = this.applicationContext;
this.applicationContext = null;
}
if (savedCtx != null && savedCtx instanceof ConfigurableApplicationContext) {
((ConfigurableApplicationContext) savedCtx).close();
}
}
}
示例9: Test2
import org.springframework.context.ApplicationContext; //导入依赖的package包/类
@Test
public void Test2(){
ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");//��ʼ������
BuildingLayoutDao buildingLayoutDao = (BuildingLayoutDao) ac.getBean("buildingLayoutDao");
BuildingLayout u = new BuildingLayout();
u.setBuildingId(2);
u.setBuildingLayout("һ��һ��");
u.setBuildingLayoutPerPrice(2);
u.setBuildingLayoutPicUrl("2112512");
u.setBuildingLayoutReferencePrice(2);
u.setBuildingLayoutSoldOut(2);
buildingLayoutDao.updateBuildingLayout(u);
System.out.println("-------");
}
示例10: refresh
import org.springframework.context.ApplicationContext; //导入依赖的package包/类
@Override
public void refresh(ApplicationContext applicationContext)
{
unResolvePostProcessList = new ArrayList<>();
Map<String, UnResolvePostProcess> unResolvePostProcessMap = applicationContext.getBeansOfType(UnResolvePostProcess.class);
if (!CollectionUtils.isEmpty(unResolvePostProcessMap)) {
unResolvePostProcessList.addAll(unResolvePostProcessMap.values());
}
unResolvePostProcessMap = null;
unResolveFieldPostProcessList = new ArrayList<>();
Map<String, UnResolveFieldPostProcess> unResolveFieldPostProcessMap = applicationContext.getBeansOfType(UnResolveFieldPostProcess.class);
if (!CollectionUtils.isEmpty(unResolveFieldPostProcessMap)) {
unResolveFieldPostProcessList.addAll(unResolveFieldPostProcessMap.values());
}
unResolveFieldPostProcessMap = null;
}
示例11: main
import org.springframework.context.ApplicationContext; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
ApplicationContext context = new AnnotationConfigApplicationContext(Application.class); // (1)
Tomcat tomcatServer = context.getBean(Tomcat.class);
tomcatServer.start();
System.out.println("Press ENTER to exit.");
System.in.read();
}
示例12: select
import org.springframework.context.ApplicationContext; //导入依赖的package包/类
@Test
public void select() {
ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");
RentHousePicDao dao = (RentHousePicDao) ac.getBean("rentHousePicDao");
RentHousePic c = new RentHousePic();
c.setRentHousePicId(2);
System.out.println(dao.selectRentHousePic(c).getPicUrl());
}
示例13: test
import org.springframework.context.ApplicationContext; //导入依赖的package包/类
@Test
public void test(){
ApplicationContext atc=new AnnotationConfigApplicationContext(SystemXml.class);
SystemXmlMap map=(SystemXmlMap)atc.getBean("systemXmlMap");
PrinterUtils.printILog(map.toString());
Environment environment=(Environment)atc.getBean("environment");
PrinterUtils.printILog(environment.getProperty("username"));
}
示例14: nettyContext
import org.springframework.context.ApplicationContext; //导入依赖的package包/类
@Bean(name="serverBrowse")
public NettyContext nettyContext(ApplicationContext context) {
HttpHandler handler = DispatcherHandler.toHttpHandler(context);
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create(host, port);
return httpServer.newHandler(adapter).block();
}
示例15: setApplicationContext
import org.springframework.context.ApplicationContext; //导入依赖的package包/类
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
XxlJobDynamicScheduler.xxlJobLogDao = applicationContext.getBean(IXxlJobLogDao.class);
XxlJobDynamicScheduler.xxlJobInfoDao = applicationContext.getBean(IXxlJobInfoDao.class);
XxlJobDynamicScheduler.xxlJobRegistryDao = applicationContext.getBean(IXxlJobRegistryDao.class);
XxlJobDynamicScheduler.xxlJobGroupDao = applicationContext.getBean(IXxlJobGroupDao.class);
}