草庐IT

webApplicationContext

全部标签

java - 如何在 spring web 应用程序运行时获取 spring-web-mvc 中的 WebApplicationContext 和 DispatcherServlet 的实例

我想在controller类下的函数中获取WebApplicationContext的实例和DispatcherServlet的实例。 最佳答案 从Spring2.5开始,您可以使用@Autowired注释获取对WebApplicationContext的引用:@AutowiredWebApplicationContextapplicationContext;您还可以通过实现ApplicationContextAware来获取ApplicationContext的引用界面:publicclassYourControllerimple

java - Springboot @ServerEndPoint "Failed to find the root WebApplicationContext."

我在使用带@ServerEndPoint注释类的spring时遇到问题我正在使用Springboot1.2.3,我正在尝试弄清楚如何拥有端点的单个实例@SpringBootApplication@EnableJpaRepositories@EnableWebSocketpublicclassApplicationServer{publicstaticvoidmain(String[]args){SpringApplication.run(ApplicationServer.class,args);}}Spring配置:@ConditionalOnWebApplication@Confi

java - 如何减少 Initializing Spring root WebApplicationContext 时间?

我知道这个问题太模糊了,任何人都无法提供解决方案,但如果需要,我可以提供更多详细信息。我的web应用程序正在使用spring,我已经将它部署到JBoss服务器,而jboss启动“初始化SpringrootWebApplicationContext”将近20分钟。我有什么选择可以减少这个吗?我在20个或更多xml文件中有近300个bean。请指教。 最佳答案 这里有一些Spring的最佳实践TIPS,将这些步骤与您的应用程序进行比较。https://developers.google.com/appengine/articles/sp

java - 如何获取默认的 WebApplicationContext?

我需要ApplicationContext.xml的上下文,我在web.xml中将其提供为org.springframework.web.context.ContextLoaderListener但是我需要在Controller类中对此进行控制。我尝试了很多东西,包括WebApplicationContextctx=ContextLoader.getCurrentWebApplicationContext();但这并没有帮助。 最佳答案 最简单的解决方案是使用getWebApplicationContext()WebApplicat

java - WebApplicationContext 不会 Autowiring

我写了这个测试类:@ContextConfiguration(locations={"classpath:/test/BeanConfig.xml"})publicclassCandidateControllerTest{@Mock(name="candidateService")privateCandidateServicecandidateService;@InjectMocksprivateCandidateMenuControllercandidateMenuController=newCandidateMenuController();@AutowiredWebApplica

java - 如何从 JAX-WS Web 服务中访问 ApplicationContext?

类似于HowcanIaccesstheServletContextfromwithinaJAX-WSwebservice?,有没有比这更容易访问applicationContext的方法?importjavax.annotation.Resource;importjavax.jws.WebService;importjavax.servlet.ServletContext;importjavax.xml.ws.WebServiceContext;importjavax.xml.ws.handler.MessageContext;importorg.springframework.web

java - 将模拟注入(inject) Spring MockMvc WebApplicationContext

我正在努力测试(通过JUnit4和SpringMockMvc)使用Spring-boot的REST服务适配器。适配器只是将向它发出的请求传递给另一个REST服务(使用自定义RestTemplate)并将额外的数据附加到响应中。我想运行MockMvc测试来执行Controller集成测试,但想用模拟覆盖Controller中的RestTemplate以允许我预定义第三个方REST响应并防止它在每次测试期间被击中。我已经能够通过实例化一个MockMvcBuilders.standAloneSetup()并将其传递给要使用此post中列出的模拟注入(inject)进行测试的Controlle

java - 如何在 Spring WebApplicationContext 中在运行时添加 bean 实例?

所以,标题很简单。我有一个处理程序类DynamicBeanHandler,它实现了spring提供的BeanDefinitionRegistryPostProcessor接口(interface)。在这个类中,我添加了多个SCOPE_SINGLETONbean,它们的bean类设置为MyDynamicBean,如下所示-GenericBeanDefinitionmyBeanDefinition=newGenericBeanDefinition();myBeanDefinition.setBeanClass(MyDynamicBean.class);myBeanDefinition.se

java - 如何在 Spring WebApplicationContext 中在运行时添加 bean 实例?

所以,标题很简单。我有一个处理程序类DynamicBeanHandler,它实现了spring提供的BeanDefinitionRegistryPostProcessor接口(interface)。在这个类中,我添加了多个SCOPE_SINGLETONbean,它们的bean类设置为MyDynamicBean,如下所示-GenericBeanDefinitionmyBeanDefinition=newGenericBeanDefinition();myBeanDefinition.setBeanClass(MyDynamicBean.class);myBeanDefinition.se

spring security 没有找到 WebApplicationContext

我是SpringSecurity新手我有web.xmlcontextConfigLocation/WEB-INF/applicationContext-security.xmlspringorg.springframework.web.servlet.DispatcherServlet1spring*.htmlspringSecurityFilterChainorg.springframework.web.filter.DelegatingFilterProxyspringSecurityFilterChain/*index.htmlapplicationContext-securit