Tag: applicationcontext

为什么我必须在@Constructor注释注释的Spring配置类中有一个默认构造函数?

我正在攻读Spring Core认证,并且根据所提供的学习内容,我有这个问题,但我无法给出答案。 为什么必须在@Configuration注释类中使用默认构造函数? 我没有将任何构造函数声明为@Configuration批注注释的配置类。 默认构造函数是超类inheritance的构造函数? 或者是什么? 为什么我必须有一个默认的构造函数,我不能覆盖它? TNX

Spring Mvc java.io.FileNotFoundException – ApplicationContext.xml

applicationContext.xml在WEB-INF文件夹中,为什么我收到此错误: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist 在web.xml org.springframework.web.context.ContextLoaderListener log4jConfigLocation /WEB-INF/classes/log4j.properties org.springframework.web.util.Log4jConfigListener org.springframework.web.context.ContextLoaderListener crimetrack org.springframework.web.servlet.DispatcherServlet 1 crimetrack *.htm index.jsp /spring /WEB-INF/tld/spring-form.tld

类加载应用程序上下文Spring

我有一个Spring Web项目,我需要在初始化应用程序上下文后加载一些类,因为这些类最终将在未来使用。 因此,我尝试在使用前预加载它们以提高性能。 怎么做 ? 请帮忙。 谢谢。

JRuby PermGen空间不足甚至在ruby代码中使用java对象

描述: 如果我们使用java对象jruby也得到permgen: System.out.println(“Initialazing..”); //Spring applicaton context WebApplicationContext wac = (WebApplicationContext) AppContext.getApplicationContext(); // prepare path to internal ruby String scriptsPath = wac.getServletContext().getRealPath(RUBY_PATH); String jrubyHome = wac.getServletContext().getRealPath(“WEB-INF” + File.separator + “jruby”); // Initializing Scripting container ScriptingContainer container = new ScriptingContainer(isShared ? LocalContextScope.SINGLETHREAD : LocalContextScope.THREADSAFE, LocalVariableBehavior.PERSISTENT); // Configuring scriptingcontainer to avoid memory leaks container.setCompileMode(RubyInstanceConfig.CompileMode.OFF); System.setProperty(“org.jruby.embed.compilemode”, “OFF”); System.setProperty(“jruby.compile.mode”, “OFF”); […]

如何将本地文件名传递给ClassPathXmlApplicationContext?

“本地文件名”是指资源文件与类文件位于同一目录中。 在下面的例子中,这是JUnitRunner.class文件。 如果路径不以/ ‘开头,那么Java的getResource()文件可以处理这个问题 我无法弄清楚,如何做同样的ClassPathXmlApplicationContext构造函数? package springtests; import java.io.File; import java.net.URISyntaxException; import java.net.URL; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.support.ClassPathXmlApplicationContext; public class JUnitRunner { private final static Logger log = LoggerFactory.getLogger(JUnitRunner.class); @Test public void test() throws URISyntaxException { String filename = “test01.xml”; URL url = getClass().getResource(filename); File file = new File(url.toURI()); log.info(“File exists: {}”, […]

Dispatcher-servlet无法映射到websocket请求

我正在开发一个以Web为主框架的Java webapp(Spring核心,Spring mvc,Spring安全,Spring数据,Spring websocket特别使用)。 在这样的Spring上下文中声明一个消息代理,为上下文提供了一个SimpMessagingTemplate bean: 我必须将此标记放在我的根上下文(applicationContext.xml)中,否则在该根上下文中声明的服务不能通过websocket向用户发送通知(因为它们需要SimpMessagingTemplate)。 问题是,如果我将此标记放在根上下文中,客户端在订阅websocket时会获得404。 如果我将标记放在dispatcher-servlet中,那么根上下文中的服务就不能发送通知,因为它们需要SimpMessagingTemplate(但它只能在子dispatcher-servlet上下文中使用)。 有没有办法将调度程序-servlet“绑定”到代理? 两次声明bean不是一个正确的解决方案。 这个问题和Spring一样:如何将SimpMessagingTemplate bean暴露给root上下文? 但从另一个角度看(在根上下文中而不是在dispatcher-servlet中声明websocket)

Spring ApplicationContext.getBean(Class c)不适用于代理类

我需要通过他们的类类型查找bean。 当bean被代理包装时(某些方法是@Transactional) – ApplicatoinContext无法找到它们。 我发现,如果我通过接口查找它们,它可以工作,但在这种情况下,我正在使用具体的类类型。 我知道bean是我正在寻找的类型,但getBean()方法失败。 我可以调试(并修复)Spring的AbstractBeanFactory代码中的问题。 问题是它根据我要请求的类型检查beanInstance的类型,但beanInstance.getClass()是一个代理。 AbstractBeanFactory应该对此进行补偿,并将类型与代理的目标类进行比较。 我有一个修复此问题,但我不特别想使用修补版本的Spring,我怀疑必须有一些我可以配置来使这个工作,或者这真的是一个错误?

自动装入列表时的Bean顺序

我已经定义了一个接口IWorker ,它的一些实现作为WorkerA和WorkerB ,都用@Component注释。 然后我通过以下方式将它们自动装入我的应用: @Autowired private List workers = new ArrayList(); 工人被列入清单的顺序取决于什么? 如何通过我的applicationContext.xml将未使用@Component注释的其他WorkerC和WorkerD (也是IWorker实现)自动装入同一列表? 是否保留了xml中WorkerC和WorkerD的顺序? 是否有一条规则可以依赖于工人A,B,C和D将被列入清单的顺序?

解析applicationContext.xml会呈现一个`java.lang.NoSuchMethodError`。 这可能是由依赖问题引起的吗?

我正在使用带注释的应用程序上下文调用测试方法(Junit)( @ContextConfiguration(locations={“classpath:applicationContext.xml”}) )。 测试失败,出现以下堆栈跟踪: 11:20:39.793 [main] ERROR ostest.context.TestContextManager – Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@28419cd] to prepare test instance [com.atrioom.TestDynamo@7fbdc7db] java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:91) ~[spring-test-4.1.1.RELEASE.jar:4.1.1.RELEASE] at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:74) ~[spring-test-4.1.1.RELEASE.jar:4.1.1.RELEASE] at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:116) ~[spring-test-4.1.1.RELEASE.jar:4.1.1.RELEASE] at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:82) ~[spring-test-4.1.1.RELEASE.jar:4.1.1.RELEASE] at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:212) ~[spring-test-4.1.1.RELEASE.jar:4.1.1.RELEASE] at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:199) [spring-test-4.1.1.RELEASE.jar:4.1.1.RELEASE] at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:251) [spring-test-4.1.1.RELEASE.jar:4.1.1.RELEASE] at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit-4.11.jar:na] at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:253) [spring-test-4.1.1.RELEASE.jar:4.1.1.RELEASE] at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:216) [spring-test-4.1.1.RELEASE.jar:4.1.1.RELEASE] […]

带有来自Jar的多个XML文件的Spring ApplicationContext

我需要使用当前Maven构建中的“main”applicationContext -a.xml创建一个ApplicationContext。 另一个来自另一个maven构建的连接类,并在Maven依赖项包含的jar中预设。 这个想法: ApplicationContext context = new ClassPathXmlApplicationContext( new String[] { “classpath*:applicationContext-*.xml”}); 这应该从Classpath加载applicationContext-a.xml,因为它在同一个Project中。 这很有效。 然后应该从dependency-jar加载applicationContext-b.xml。 这不起作用。 注意 “classpath*:applicationContext-*.xml” 只匹配直接类路径中的XML,jar中没有任何内容。 我发现了什么: ApplicationContext context = new ClassPathXmlApplicationContext( new String[] { “classpath*:applicationContext-*.xml”, “classpath*:applicationContext-b.xml”}); 这是有效的,但前提是我可以在jar:applicationContext-b.xml中明确告诉xml的文件名 我还需要它来进行集成测试: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {“**/applicationContext*.xml”}) public class TestClass { … } 最好的想法可能是自定义装载机? 必须有一种方法来使这个模式工作…… 前段时间有一个解决方案 ,反之亦然:它只从jar获取applicationContext.xml。 如果类路径中有另一个,它只匹配此文件。