Spring JDBC,无法打开ServletContext资源

时间:2016-05-09 20:26:45

标签: java database spring spring-mvc jdbc

我不明白为什么这段代码不起作用。我按照网站的步骤跟踪了指导步骤" http://www.tutorialspoint.com/spring/spring_injecting_collection.htm"完美。你能帮助我吗?

抛出异常的类:

showPrice

这是调度程序servlet:

public class UserJDBCTemplate implements UserDao {
private DataSource dataSource;
private JdbcTemplate jdbcTemplateObject;

@Override
public void setDataSource(DataSource dataSource) {
    System.out.println(dataSource.toString());
    this.dataSource = dataSource;
    this.jdbcTemplateObject = new JdbcTemplate(dataSource);     
}

public DataSource getDataSource() {
    return dataSource;
}
enter code here
 @Override
public void create(String first_name, String last_name, String role,   

String password, String username, String email, String avatar, String`enter code here` chat_code) {     
    String SQL = "insert into user (first_name, last_name, role, password, username, email, avatar, chat_code) values ( ?, ?, ?, ?, ?, ?, ? , ?)";
    jdbcTemplateObject.update( SQL, first_name, last_name, role, password, username, email, avatar, chat_code);
      //log.info("Created Record Name = " + name + " Age = " + age)     
}

这是contextApplication:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" 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 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<mvc:annotation-driven />   
<context:component-scan base-package="com.wbm.bug_presents" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/WEB-INF/views/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>

这是web.xml文件

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" 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 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
   <bean name = "dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
      <property name="url" value="jdbc:mysql://localhost:3306/wbm_bug_track_svil"/>
      <property name="username" value="eugen"/>
      <property name="password" value="eugen"/>
   </bean>
   <bean id="addBugJDBCTemplate" class="com.wbm.bug_presents.JDBCTemplate.AddBugJDBCTemplate">
      <property name="dataSource"  ref="dataSource" />    
   </bean>
   <bean id="chatBugJDBCTemplate" class="com.wbm.bug_presents.JDBCTemplate.ChatBugJDBCTemplate">
      <property name="dataSource"  ref="dataSource" />    
   </bean>
   <bean id="removeBugJDBCTemplate" class="com.wbm.bug_presents.JDBCTemplate.RemoveBugJDBCTemplate">
      <property name="dataSource"  ref="dataSource" />    
   </bean>
   <bean id="userJDBCTemplate" class="com.wbm.bug_presents.JDBCTemplate.UserJDBCTemplate">
      <property name="dataSource"  ref="dataSource" />    
   </bean>

错误是:

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>bug-presents</display-name>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/contextApplication.xml</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
    <servlet-name>SpringDispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/SpringDispatcher-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>SpringDispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
    <welcome-file>/WEB-INF/views/login.jsp</welcome-file>
</welcome-file-list>

1 个答案:

答案 0 :(得分:0)

问题的核心是自我例外:

  

无法打开ServletContext资源   [/WEB-INF/applicationContext.xml的]

正如您在评论中所写,您的配置文件名为function age(year, month, day) { var today = new Date(); var endDate = new Date(year, month, day).getTime(); var dayDiff = Math.floor((endDate - today) / 86400000); if (dayDiff >= 365) { var year = Math.floor(dayDiff / 365); var remainder = Math.floor(dayDiff) - (year * 365); var months = Math.floor(remainder / 30); } else { var year = 0; var remainder = Math.floor(dayDiff) - (year * 365); var months = Math.floor(remainder / 30); } var days = Math.floor(remainder) - (months * 30); return year + " years" + " " + months + " months" + " " + days + " days"; } document.write("<p>" + age(2017, 11, 17) + "</p>"); document.write("<p>" + age(2016, 7, 11) + "</p>");,因此您必须将其更改为contextApplication.xml