简体   繁体   English

在WebApp上下文中,“ spring-context.xml”文件在哪里?

[英]Where does the “spring-context.xml” file go in a WebApp context?

In short: I don't know which folder to place the "spring-context.xml" file in a WebApp when I'm doing this: 简而言之:执行此操作时,我不知道将哪个文件夹放置“ spring-context.xml”文件到WebApp中:

ApplicationContext context = new ClassPathXmlApplicationContext("spring-context.xml");

In Long: I know what a classpath is basically. 在朗:我知道什么是类路径。 It used to be an environment variable that told the Java project where to look for jars and other resources. 它曾经是一个环境变量,它告诉Java项目在哪里寻找jar和其他资源。 It doesn't seem to be used much. 它似乎使用不多。 But in Eclipse, it talks about setting your classpath by going into your Java Build Path. 但是在Eclipse中,它讨论通过进入Java Build Path来设置类路径。

What I don't understand it when I want to find a Spring "spring-context.xml" file using the classpath (above) what that has to do with the Eclipse Java Build Path, if anything! 当我想使用classpath查找一个Spring“ spring-context.xml”文件时,我不了解它(上面)与Eclipse Java Build Path有什么关系! What folders does a WebApp look in when I use the above statement? 当我使用上面的语句时,WebApp将查找哪些文件夹? I usually hear people say, "In the classpath" but that doesn't tell me much since I don't want to use an environment variable and the Eclipse Java Build Path seems to have little to do with finding the spring-context.xml file. 我通常会听到人们说“在类路径中”,但这并不能告诉我太多,因为我不想使用环境变量,并且Eclipse Java构建路径似乎与找到spring-context.xml无关。文件。

More Detail 更多详情

Initially I was afraid that more details would confuse the situation, but maybe they hold a key. 最初,我担心更多细节会使情况混乱,但也许它们掌握了关键。

I am using Vaadin to create a web app. 我正在使用Vaadin创建一个Web应用程序。 I'm following their direction for how to get a Spring context into Vaadin. 我正在按照他们的指示来指导如何将Spring上下文引入Vaadin。 I've created a Spring Helper class: 我创建了一个Spring Helper类:

public SpringContextHelper(Application application) {
    ServletContext servletContext = ((WebApplicationContext) application.getContext()).getHttpSession().getServletContext();
    context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
}

In the web.xml I have these sections: web.xml ,有以下部分:

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:spring-context.xml</param-value>
</context-param>

I'm getting the error in the first line of SpringContextHelper() . 我在SpringContextHelper()的第一行中遇到了错误。 I've broken the line down so I know it is this logic that is failing: 我已经把这条线弄断了,所以我知道是这种逻辑失败了:

WebApplicationContext wac = (WebApplicationContext) application.getContext();

wac comes back null, presumably because is can't find the spring-context.xml file. wac返回null,大概是因为找不到spring-context.xml文件。

Essentially, the "Java Build path" you specify for a project is the CLASSPATH. 本质上,您为项目指定的“ Java构建路径” CLASSPATH。

And files you put in the "src" root of your "Java Resources" project folder will automatically go in your web app's "classes" subdirectory (ie will automatically be available as in the runtime CLASSPATH). 放在“ Java资源”项目文件夹的“ src”根目录中的文件将自动进入Web应用程序的“类”子目录(即,在运行时CLASSPATH中将自动可用)。

For example, if you have a custom log4j.properties file, then it can and should go in your Eclipse project's "src/" root. 例如,如果您有一个定制的log4j.properties文件,那么它可以并且应该进入Eclipse项目的“ src /”根目录。

As far as "where does spring-context.xml go?", I don't know. 至于“ spring-context.xml去哪里?”,我不知道。 This link suggests it should go under META-INF/jsca (at least for WebLogic): 该链接建议它应该位于META-INF / jsca下(至少对于WebLogic):

http://docs.oracle.com/cd/E15315_09/help/oracle.eclipse.tools.weblogic.doc/html/sca.html http://docs.oracle.com/cd/E15315_09/help/oracle.eclipse.tools.weblogic.doc/html/sca.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM