在我的spring mvc应用程序中,当我在web.xml文件中添加applicationContext.xml时:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
当我删除标签时。这是工作文件。我如何包含applicationContext.xml
的applicationContext.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"
xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:jd="http://www.springframework.org/schema/jdbc"
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
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd">
<!-- How to include more then one base package -->
<context:annotation-config />
<context:component-scan base-package="com.ankit.controller" />
<context:component-scan base-package="com.ankit.service" />
<mvc:annotation-driven />
<!-- Below configuration has been added to enable in memory DB HSQLDB -->
<!-- <jd:embedded-database id="dataSource1" type="HSQL">
<jd:script location="classpath:schema.sql" />
<jd:script location="classpath:test-data.sql" />
</jd:embedded-database> -->
<bean id="SpringJdbcDao" class="com.ankit.dao.impl.SpringJdbcDaoImpl">
<!-- <property name="dataSource" ref="dataSource1" /> -->
</bean>
<bean id="springJdbcService" class="com.ankit.service.impl.SpringJdbcServiceImpl">
<property name="springJdbcDao" ref="SpringJdbcDao" />
</bean>
</beans>
FirstController.java
package com.ankit.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.ankit.beans.Employee;
@Controller
public class FirstController {
@Autowired
com.ankit.service.SpringJdbcService springJdbcService;
@RequestMapping(value = "/searchJdbcContact", method = RequestMethod.GET)
public ModelAndView searchContact() {
Employee vngmem=new Employee()
Employee bean = springJdbcService.searchMemDts(vngmem);
return new ModelAndView("hello", "message", bean);
}
}
SpringJdbcService.java
package com.ankit.service;
import com.ankit.beans.Employee;
public interface SpringJdbcService {
Employee searchMemDts(Employee vngmem);
void insertMemDts(Employee MemDtlsbean);
}
SpringJdbcServiceImpl.java
package com.ankit.service.impl;
import org.springframework.jdbc.BadSqlGrammarException;
import org.springframework.stereotype.Service;
import com.ankit.beans.Employee;
import com.ankit.service.SpringJdbcService;
@Service
public class SpringJdbcServiceImpl implements SpringJdbcService {
public Employee searchMemDts(Employee vngmem) {
try {
vngmem.setEmployeeName("Ankit");
return vngmem;
} catch (BadSqlGrammarException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
我正试图点击此网址: 本地主机:8085 / MVC / searchJdbcContact.html