【java – 添加了Spring Security,现在我收到“没有找到WebApplicationContext:没有注册ContextLoaderListener?”】教程文章相关的互联网学习教程文章

java – spring – ApplicationContext registerBean自动装配失败,但getBean在Spring 5中工作【代码】

我正在使用一个使用动态bean注册的配置类:@Configuration public class ConfigClass {@Autowiredprivate GenericApplicationContext applicationContext;@PostConstructprivate void init() {System.out.println("init");applicationContext.registerBean("exService", ExecutorService.class, () -> Executors.newFixedThreadPool(10), bd -> bd.setAutowireCandidate(true));System.out.println("init done");} }如果我尝试自动...

java – 将参数传递给ApplicationContext【代码】

我的应用程序我有一个application-context.xml.现在我将ApplicationContext实例化为:ApplicationContext context = new ClassPathXmlApplicationContext("application-context.xml");是否可以通过此实例化传递参数,以便这些参数可用于初始化某些bean的某些属性? PS:不使用属性文件.由于参数是生成运行时间,如可解决的jar的位置,系统架构,os名称等是可变的.解决方法:您可以在applicationContext.xml中使用PropertyPlaceholderCon...

为什么我得到“无法加载ApplicationContext”Spring,jUnit和JavaConfig【代码】

为什么我得到“无法加载ApplicationContext”Spring,jUnit和JavaConfig 这是我的测试类:@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = HelloWorldConfig.class) public class TestApp {@Testpublic void testBean(){ApplicationContext context = new AnnotationConfigApplicationContext(HelloWorldConfig.class);HelloWorld helloWorld = context.getBean(HelloWorld.class);helloWorld.setMessage...

java – Spring XML中applicationcontext的“this”引用【代码】

有没有办法在Spring中的bean配置文件中引用当前的应用程序上下文? 我想做这样的事情:<beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:util="http://www.springframework.org/schema/util"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframewor...

java – BeanFactory未初始化或已经关闭 – 在通过ApplicationContext访问bean之前调用’refresh’【代码】

我有这个web.xml文件<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-context.xml /WEB-INF/core-spring-beans.xml </param-value> </context-param><listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>和包含Bean的applicationContext<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframewo...

java – EntityManagerFactory和ApplicationContext用法【代码】

我想确保因为我使用@PersistenceContext,所以我不需要关闭任何连接,以避免泄漏和任何左开连接和性能不佳.所以我的applicationContext.xml看起来如下(我定义了entitymanager工厂等).<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="...

java – 在春天导入ApplicationContext【代码】

我正在从本教程学习Spring: http://courses.caveofprogramming.com/courses/the-java-spring-tutorial/lectures/38024 在本教程中,讲师在版本3.2.3.RELEASE中下载spring依赖项(spring-beans,spring context,spring-core). 然后写下这段代码:package com.caveofprogramming.spring.test;import org.springframework.context.ApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext;pub...

java – ApplicationContext.getBean vs new keyword【代码】

我正在使用JSF Spring Hibernateprotected @Inject ChartOfAccount chartOfAccount;我基本上想从列表中填充chartOfAccountfor (DistributionEntry de : getDistributionEntries()) {chartOfAccount.setAccount(de.getAccount());chartOfAccountList.add(chartOfAccount); }每次迭代我想chartOfAccount的新对象,否则你知道名单上有与最新值相同的对象. 解决方案一:使用新关键字:-pfor (DistributionEntry de : getDistributionEntr...

java – 在Spring ApplicationContext.xml中推送maven属性【代码】

我想将project.version从maven推送到appicationContext.xml,如下所示,<mvc:resources mapping="/static/${project.version}/**" location="/static/"/>在pom.xml中,我按如下方式配置了maven过滤器<resources><resource><directory>${basedir}/src/main/webapp/WEB-INF</directory><filtering>true</filtering><includes><include>**/applicationContext.xml</include></includes></resource></resources>过滤器工作正常,但applicat...

java – 在销毁ApplicationContext之前立即触发的Spring关闭事件?

我正在寻找一个拦截器或触发器来知道,所有上下文bean都被销毁,applicationcontext实例将要自行销毁.所以我可以在应用程序生命周期结束时执行一个过程. 有一个事件类型ContextClosedEvent,它接近我想做的事情,但它会在销毁bean之后抛出事件.我认为它与applicationcontext的close()方法有关.所以它不符合我的需要 有任何想法吗? 问候 阿里解决方法:您可以使用抽象应用程序上下文类的registerShutDownHook()方法.有关详细信息,请查看...

java – 如何在junit @BeforeClass静态方法中访问spring ApplicationContext?【代码】

我试图通过:private static ApplicationContext applicationContext; @Autowiredpublic static void setApplicationContext(ApplicationContext applicationContext) {AuditorTest.applicationContext = applicationContext;}但它并不像所有其他尝试那样有效. 如何自动装配静态ApplicationContext?解决方法:你不能在静态方法上自动装配spring bean.你要把它变成一个实例方法,然后让它将值赋给静态变量(这样可以正常工作):@Autow...

java – Spring的ApplicationContext的静态Singleton实例

我正在尝试将使用CURAM编写的应用程序移植到Struts2项目中.我们正在使用Spring来利用其数据库事务功能.对应用程序代码在CURAM应用程序中编写的方式,我不能使用Spring的依赖注入功能.我需要能够从业务逻辑中的任何位置访问Spring ApplicationContext.每当我需要的时候创建一个新的ApplicationContext实例就会把事情搞得一团糟. 我在互联网上找到了这个资源,它向您展示了如何创建Spring的ApplicationContext的静态单例实例. Access t...

java – 找不到applicationContext类路径【代码】

由于某种原因(shiro过滤器)我将我的应用程序上下文文件保存在WEB-INF文件夹中.当我运行tomcat但是,当我尝试从控制器获取应用程序上下文时,一切正常:context = new ClassPathXmlApplicationContext(fileContext);我总是收到这个例外:IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] can...

java – Maven将applicationContext.xml从src / main / resources复制到target / myproject / WEB-INF【代码】

目前,默认我认为,它复制到target/myproject/WEB-INF/classes因此在部署时不会获取上下文. 另外,我想引用服务器特定的配置文件database.properties,我想把它放在tomcat / conf中然后在applicationContext.xml中引用它,我该怎么做? 另外(2),我的印象是这是一个相当标准和体面的方式来设置 – 如果我错了,请纠正我. 编辑对于服务器特定的配置文件我用户这个<context:property-placeholder location="file:${catalina.home}/conf/data...

java – 使用JPA的Spring安全性.如何配置applicationContext-security.XML文件?(使用DaoAuthenticationProvider)【代码】

我正在使用JDBC身份验证服务来保护我的安全.认证提供者代码是,<authentication-provider><jdbc-user-service id="userDetailsService" data-source-ref="dataSource" /> </authentication-provider>对于数据源,<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" ><property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localho...

APPLICATION - 相关标签
LISTENER - 相关标签