<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
servlet-context.xml
<?xml version="1.0" encoding="UTF-8"?>`<br/>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"`
xmlns:context="http://www.springframework.org/schema/context"`
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd`
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd`
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">`
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<beans:import resource="application-context.xml"/></beans:beans>`
应用程序上下文. xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"`
xsi:schemaLocation="http://www.springframework.org/schema/beans`
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd`
http://www.springframework.org/schema/context`
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- SET default mail properties -->
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="mail.company.com"/>
<property name="port" value="25"/>
<property name="javaMailProperties">
<props>
<prop key="mail.transport.protocol">smtp</prop>
<prop key="mail.smtp.auth">false</prop>
<prop key="mail.smtp.starttls.enable">false</prop>
<prop key="mail.debug">false</prop>
</props>
</property>
</bean>
<bean id="applicationMailer" class="sdcounty.dcss.cat.ApplicationMailer">
<property name="mailSender" ref="mailSender" />
</bean>
</beans>
调用方法
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import sdcounty.dcss.cat.ApplicationMailer;
@RequestMapping(value = "/Error", method = { RequestMethod.POST, RequestMethod.GET })
public ModelAndView handleError(HttpServletRequest request) {`
//Create the application context
ApplicationContext context = new ClassPathXmlApplicationContext("application-context.xml");
//Get the mailer instance
ApplicationMailer mailer = (ApplicationMailer) context.getBean("applicationMailer");
//Error Message
String errorMessage = (String) request.getAttribute("javax.servlet.error.exception") + String.format("%n") +
(String) request.getAttribute("javax.servlet.error.exception_type") + String.format("%n") +
(String) request.getAttribute("javax.servlet.error.request_uri") + String.format("%n") +
(String) request.getAttribute("javax.servlet.error.servlet_name") + String.format("%n") +
//(Integer) request.getAttribute("javax.servlet.error.status_code") + String.format("%n") +
(String) request.getAttribute("javax.servlet.error.message") + String.format("%n");
//Send a composed mail
mailer.sendMail("john.doe@company.com", "Error Report", errorMessage);}
堆栈跟踪
SEVERE: Servlet.service() for servlet appServlet threw exception
java.io.FileNotFoundException: class path resource [application-context.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:157)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at sdcounty.dcss.cat.controllers.ErrorController.handleError(ErrorController.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:489)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:467)
at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:338)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:203)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
尝试使用
强制实施类路径资源
我多年来一直在使用Spring MVC,我试图理解与Spring Boot的一些关键区别。 你能帮我确认一下吗?或者让我明白我在这里遗漏了什么?
Spring Boot对于如何使用Spring构建应用程序有一个看法:例如它具有常规配置文件的常规位置,以及用于常见管理和监视任务的端点。Spring Cloud建立在此之上,并添加了一些可能系统中所有组件将使用或偶尔需要的功能。 引导应用程序上下文 一个Spring Cloud应用程序通过创建一个“引导”上下文来进行操作,这个上下文是主应用程序的父上下文。开箱即用,负责从外部源加载配置属性,还解
问题内容: 有没有办法在Spring应用程序中静态/全局地请求ApplicationContext的副本? 假设主类启动并初始化了应用程序上下文,它是否需要通过调用堆栈将其向下传递给需要它的任何类,或者是否有一种方法可以让类要求先前创建的上下文?(我认为必须是单身人士?) 问题答案: 如果需要访问容器的对象是容器中的Bean,则只需实现BeanFactoryAware或ApplicationCon
我第一次手工将AngularJS和spring boot应用程序连接在一起。我遇到的问题是@RestController没有返回索引页: 目录: 它会继续呈现默认的404错误页面: ----------------更新1------------------ 我添加了一个配置文件: 重新控制器 主要类别: 上面的主类仍然返回默认的404错误页面。
只有当用户经过身份验证时,我才能在JSP页面中显示注销链接。在JSP页面的这一行有一个例外: 例外情况: 这是我的应用程序上下文安全性。xml: 我知道我可以在http标记中使用expression=“true”,但这意味着我必须在intercept url标记和java代码中使用expression。有解决办法吗?