Struts2 Spring3 基於註解的配置

2021-09-02 09:39:35 字數 2367 閱讀 5940

web.xml

<?xml version="1.0" encoding="utf-8"?>

contextconfiglocation

org.springframework.web.context.contextloaderlistener

struts2

org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter

/*index.jsp

<?xml version="1.0" encoding="utf-8"?>

struts2配置 放在scr目錄下

<?xml version="1.0" encoding="utf-8"?>

contextconfiglocation

org.springframework.web.context.contextloaderlistener

struts2

org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter

/*index.jsp

action寫法  目錄:src.com.action

package com.action;

import org.apache.struts2.convention.annotation.action;

import org.apache.struts2.convention.annotation.namespace;

import org.apache.struts2.convention.annotation.result;

import org.apache.struts2.convention.annotation.results;

import org.apache.struts2.convention.annotation.parentpackage;

import org.springframework.beans.factory.annotation.autowired;

import com.opensymphony.xwork2.actionsupport;

import com.service.personservice;

@namespace("/person") //訪問路徑的包名

@results( )

public class personaction extends actionsupport

@action("login") //訪問路徑的action名, 想要訪問seluser 這個方法 位址為 http://localhost:8080/工程名/yang/login

public string seluser()

}

dao 寫法  目錄:src.com.dao.impl  介面在 src.com.dao 此處略

package com.dao.impl;

import org.springframework.stereotype.repository;

import com.dao.persondao;

@repository("persondao")

public class persondaoimpl implements persondao

@override

public void selperson()

}

service 寫法 目錄:src.com.service.impl,介面在 src.com.service 此處略

package com.service.impl;  

import org.springframework.beans.factory.annotation.autowired;

import org.springframework.stereotype.service;

import com.dao.persondao;

import com.service.personservice;

@service("personservice")

public class personserviceimpl implements personservice

@override

public void selperson()

}

注意增加這個jar包  其他spring包,struts包自備

struts2-spring-plugin-2.3.16.jar 

來自:

框架整合之struts2 spring3

在整合struts2和spring3的時候還費了挺大的勁兒 現整合方法如下,希望路過的大神指教 struts2中的struts2 spring plugin xx.xx.xx.jar xx意思就是版本數字的意思 路徑引進專案中,然後在你的spring的配置檔案中配置注入的bean,如下 再在stru...

struts2 spring 整合 配置

1 在eclipse中配置好struts2 2 把struts2 spring plugin 2.0.11.2.jar包複製到web inf lib目錄 3 在web.xml中配置spring org.springframework.web.context.contextloaderlistener...

Struts 2框架整合Spring

struts 2框架整合spring很簡單,下面是整合的步驟。1.複製檔案。複製struts2 spring plugin x x x.jar和spring.jar到web inf lib目錄下。其中的x對應了spring的版本號。還需要複製commons logging.jar檔案到web inf...