struts2整合spring无法注入bean

    今天搭建了一个strut2 + spring + mybatis的程序,在做登陆功能的时候,service的bean死活都注入不进action的类中,还以为是spring没有注入进去,最后发现时差了一个包,伤心~加入 struts2-spring-plugin.jar后问题解决。下面是个简单spring注入的例子

    pom.xml部分

<!-- Struts2 start -->
	<dependency>
		<groupId>org.apache.struts</groupId>
		<artifactId>struts2-core</artifactId>
		<version>2.3.15.2</version>
	</dependency>
	
	<dependency>
		<groupId>org.apache.struts</groupId>
		<artifactId>struts2-spring-plugin</artifactId>
		<version>2.3.15.2</version>
	</dependency>
	<!-- Struts end --> 
        <!-- spring start -->
   	<dependency>
	  	<groupId>org.springframework</groupId>
	  	<artifactId>spring-test</artifactId>
	  	<version>${spring.version}</version>
	</dependency>
	            
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-orm</artifactId>
		<version>${spring.version}</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-core</artifactId>
		<version>${spring.version}</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-aop</artifactId>
		<version>${spring.version}</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-beans</artifactId>
		<version>${spring.version}</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-context</artifactId>
		<version>${spring.version}</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-webmvc</artifactId>
		<version>${spring.version}</version>
	</dependency>
	<!-- spring end -->

    web.xml
    

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring/applicationContext.xml</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
    applicationContext.xml,注解模式注入
<context:annotation-config/>
<context:component-scan base-package="org.hhw"/>
    service层

    action
struts2整合spring无法注入bean


你可能感兴趣的:(spring)