spring会自动代理Struts2的action 50C

我的struts的action全部被spring配置成了aop,我的action出现的全部是代理对象。
导致我的action不能调用自己定义的方法。为什么我没有配置struts的action为aop,
但是spring全部自动配置成了aop?这spring的配置文件

 <?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:aop="http://www.springframework.org/schema/aop"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                http://www.springframework.org/schema/aop
                http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<!-- 启用注解扫描 -->
<context:annotation-config/>
<!-- spring默认只代理Action类的接口的函数,cglib jar文件就是可以代理Action自己定义的函数 
<aop:aspectj-autoproxy proxy-target-class="true" />
-->
<bean id="testService" class="com.guoqiao.test.TestService">
    <property name="name" value="test"/>
</bean>
<!-- 配置数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
        <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:orclguo"/>
        <property name="username" value="scott"/>
        <property name="password" value="tiger"/>
         <!-- 连接池启动时的初始值 -->
        <property name="initialSize" value="30"/>
        <!-- 连接池的最大值 -->
        <property name="maxActive" value="500"/> 
        <!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 -->
        <property name="maxIdle" value="2"/>
        <!--  最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 -->
        <property name="minIdle" value="1"/>
</bean>
<!-- 配置会话工厂() -->
<bean id="sessionFactory"  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
     <!-- 设置数据源 -->
     <property name="dataSource" ref="dataSource"/>
     <!-- 接管了hibernate对象映射文件 -->
     <property name="mappingResources">
        <list>     
          <value>com/guoqiao/domain/Department.hbm.xml</value>
          <value>com/guoqiao/domain/Employee.hbm.xml</value>
        </list>
     </property>
     <property name="hibernateProperties">
        <value>
                hibernate.dialect=org.hibernate.dialect.OracleDialect
                hibernate.hbm2ddl.auto=update
                hibernate.show_sql=true
                hibernate.cache.use_second_level_cache=true
                hibernate.cache.use_query_cache=true
                hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
                hibernate.generate_statistics=true        
        </value>
     </property>
</bean>
<!--
<bean id="employeeService" class="com.guoqiao.service.imp.EmployeeService">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>
  -->
<!-- 配置EmployeeService对象通过注解的方式来注入属性值,这是一个知识点 -->
<bean id="employeeService" class="com.guoqiao.service.imp.EmployeeService"/>

<bean id="departmentService" class="com.guoqiao.service.imp.DepartmentService">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 配置事务管理器,统一管理sessionFactory的事务 -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>

<!-- 启用事务注解 @Transactional-->
<tx:annotation-driven transaction-manager="txManager"/>
</beans>

明白点说就是我spring中的bean全部都被spring代理了,包括我struts2的action.
举个例子,我有个叫employee的bean

 <bean id="employeeService" class="com.guoqiao.service.imp.EmployeeService">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

public interface EmployeeServiceInterf{
public void a();
}
public class EmpolyeeService implements EmployeeServiceInterf{
public void b(){
System.out.println("b");
};
public void a(){
System.out.println("a");
};
}

public class TestInjection(){
//下面的写法注入不了
EmpoyeeService employeeService;
//下面的写法可以注入
EmpoyeeServiceInterf employeeService;
}
这是一个bean,这个Bean类是EmpoyeeService
EmpoyeeService实现了EmployeeServiceInterf接口
但我是把这个bean注入类型为EmpoyeeService的对象上会注入失败
把这个bean注入EmployeeServiceInterf的对象上时才能成功(在spring集成struts2的环境中)

再明白点说就是说这个bean看起来像是一个实现类,但其实你用这bean注入其他对象
上的时候,这个bean是这个实现类的代理对象。

如果上面我手动写的代码还看不懂的话,你还是绕道吧,你连我讲的是什么都看不懂。

3个回答

/context:component-scan这个才是扫描注释的

context:annotation-config/

这一段里把不就是自动配置的语句吗······你没发现这里注释的不对吗······把这些都注释在一起

gq6547017
大鸵鸟 不懂你说什么,我的注解没问题的就是少了句<context:component-scan base-package="XXX" />
3 年多之前 回复

配置文件中已经引入了context,使用context标签试一下。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
spring 的自动代理
spring实现的自动代理配置!用到的关键类org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator
Spring AOP的自动代理
一般情况下的代理针对每一个对象的只能增强都需要新建一个bean标签,当有很多类的时候就显得比较繁琐,这时Spring为我们提供了自动代理 情况1:BeanNameAutoProxyCreator    根据Bean的名称来创建代理 配置:修改一般情况下的代理类ProxyFactoryBean为BeanNameAutoProxyCreator <bean class="org.
Spring 顾问 自动代理
[java] view plain copy public interface IDog1 {       public  void  dog();       public  void  run();   }   public class MyAfter implements AfterReturningAdvice {       public void
Spring自动代理
转载自:http://bolide74.iteye.com/blog/1049935   这是《Spring温故知新》系列的第一部基础部分的最后一篇,简单的介绍一下Spring的自动代理。 我一直都用机器人打招呼这个小应用来做举例,可能大家感觉用了前一篇的CGLIB代理以后就已经是非常方便了。但是事实上如果是真正大型的企业应用来说这还远远不够方便。 不管是动态代理还是CGLIB代理,它们在使...
Spring的自动代理
spring默认提供的几种auto-proxy:    BeanNameAutoProxyCreator   :  可以配置需要被进行auto-proxy的bean names列表,它控制的是需要代理的bean列表InfrastructureAdvisorAutoProxyCreator  DefaultAdvisorAutoProxyCreator :  将对应匹配的advisor,
自动代理生成器
public interface ISomeService { public void doSome(); public void dade(); } public interface ISomeService1 { public void doSome(); public void dade(); } import org.sp...
spring 自动代理
[size=large][b]spring 自动代理[/b][/size] [size=large] 1、org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator 2、org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCrea...
spring 自动代理的问题
以下是我xml中的BEAN配置文件: rnrn rn rn rn rn rn rn welcomePonintcutAdvice rn bybyPointcutAdviec rn aroundPointCutAdvice rn exceptionAdvice rn modifiedTimeAdvisor rn rn rn rnrn rnrn rn rn rn *Service rn rn rn rn rn welcomePonintcutAdvice rnrn rn rn rnrn rnrn rn
struts2 的action 会执行两次
小弟在做网站的时候遇到action会被执行两次的情况,在网上找了资料,也没能解决。rn首先我在index的页面写了一个链接rn[code=HTML]rn123rn[/code]rn这个页面跳转到EmployeesPage这个actionrn代码如下rn[code=XML]rnrn /EmployeesAddPage.jsp rnrn[/code]rnmethod go的方法如下:rn[code=Java]rnpublic String go() rn QsCtypeDao ctypeDao = new QsCtypeDao();rn ctype = ctypeDao.findAll();rn System.out.println("123");rn return "addPage";rn rn[/code]rn输出的时候 控制台有2个123 并有警告。rnrn123rn2011-6-19 11:31:02 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warnrn警告: No configuration found for the specified action: '/Employees/EmployeesAdd' in namespace: '/Employees'. Form action defaulting to 'action' attribute's literal value.rn2011-6-19 11:31:02 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warnrn警告: No configuration found for the specified action: '/Employees/EmployeesAdd' in namespace: '/Employees'. Form action defaulting to 'action' attribute's literal value.rn2011-6-19 11:31:02 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warnrn警告: No configuration found for the specified action: '/Employees/EmployeesAdd' in namespace: '/Employees'. Form action defaulting to 'action' attribute's literal value.rn2011-6-19 11:31:02 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warnrn警告: No configuration found for the specified action: '/Employees/EmployeesAdd' in namespace: '/Employees'. Form action defaulting to 'action' attribute's literal value.rn123rnrn各位大大有没有遇到过类似的情况?如何解决呢?rnrn
spring aop struts2 action的问题
我想用spring aop来切struts2中指定的方法 但不是知道为什么老报方法找不到错误 rn而且我用spring aop 来同时管理事务时 却很正常 dao层出错 service层方法能做到事务的处理 也能回滚rn但就是不能毁 action中的方法 老是NoSuchMethod .郁闷......rnrn我的spring的配置如下 rn[code=XML]rnrnrnrnrn rn rn rn rn rn rnrn[/code]rn[code=Java]rnpackage com.test.web.action;rnrnimport java.text.SimpleDateFormat;rnimport java.util.Calendar;rnrnimport javax.servlet.http.HttpServletRequest;rnrnimport org.apache.struts2.ServletActionContext;rnrnpublic class CheckAuthorAction //这是个strut2的 action类,验证成功就继续执行 rn //失败就返回登录页面rn private String from ;rn public String checkAuthority() //我想用这个方法处理我的切点 原意是想对用户身份做验证rn //测试时就简单点 用时间测试 rn rn Calendar cal = Calendar.getInstance();rn SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");rn HttpServletRequest request = ServletActionContext.getRequest();rn String time = sdf.format(cal.getTime());rn String[] times = time.split("-");rn if("10".equals(times[2])) rn rn String path = request.getContextPath();rn String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";rn String servletPath = request.getServletPath();rn rn from = basePath+servletPath ;rn System.out.println("aop 验证时,通过验证......................................................");rn return "checkAuthorPass" ;rn elsern request.setAttribute("error_message","aop 验证时,发现用户没有登录");rn System.out.println("aop 验证时,发现用户没有登录.....................................................");rn return "checkAuthorFail" ;rn rn rn public String getFrom() rn return from;rn rn public void setFrom(String from) rn this.from = from;rn rnrn[/code]rnrn[code=Java]rnpackage com.test.web.action;rnrnimport java.sql.Timestamp;rnimport java.util.List;rnrnimport org.apache.struts2.ServletActionContext;rnrnimport com.opensymphony.xwork2.ActionSupport;rnimport com.test.persistent.entity.Notice;rnimport com.test.service.iservice.NoticeService;rn //有网友说不要继承ActionSupport我也做了 不继承和继承我都试了 都不行呀rnrnpublic class NoticeAction rn private NoticeService noticeService;rn private int id;rn private String noticeTitle;rn private String noticeContent;rn private int noticeSort;rn private String ids;rn private int startRow;rn private String to_page;rn public String showNotices()rn tryrn List notices=noticeService.showNotices();rn ServletActionContext.getRequest().setAttribute("notices", notices);rn return to_page;rn catch(Exception e)rn rn return "error";rn rn rn public void setIds(String ids) rn this.ids = ids;rn rn public void setstartRow(int startRow) rn this.startRow = startRow;rn rn public void setId(int id) rn this.id = id;rn rn public void setNoticeContent(String noticeContent) rn this.noticeContent = noticeContent;rn rn public void setNoticeService(NoticeService noticeService) rn this.noticeService = noticeService;rn rn public void setNoticeSort(int noticeSort) rn this.noticeSort = noticeSort;rn rn public void setNoticeTitle(String noticeTitle) rn this.noticeTitle = noticeTitle;rn rnrnrn[/code]rn rnrn2009-9-10 9:55:04 org.apache.catalina.core.StandardWrapperValve invokern严重: Servlet.service() for servlet default threw exceptionrnjava.lang.NoSuchMethodException: $Proxy41.showNotices()rn at java.lang.Class.getMethod(Unknown Source)rn at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.getActionMethod(AnnotationValidationInterceptor.java:55)rn at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:41)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)rn at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)rn at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)rn at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)rn at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)rn ...
【ssh学习笔记】struts2的action与Spring
//由struts-spring-plugin管理,不需要加@Resource,或在applicationContext.xml中也不需要配置该bean//需要注入的对象也不需要加@Resourcepublic class JsonAction extends ActionSupport { /** * */ private static final long serialVers
Struts2 的Action能否自动触发
我看了几天struts的书,感觉struts 的Action Class都是在form的post方法里触发的rn这样,如果我有个页面没有按钮或者 而想和后台交互,应该怎么写呢?rnrn请教高手~~~~~
关于Struts2中action会自动执行自定义的方法吗?
public String execute() throws Exception n return "hello";n n //log方法,Action调用的method方法n public String log()throws Exceptionn System.out.println("log");n return "hello";n n //校验方法n public void validate() n System.out.println("validate");n n //log method的校验方法n public void validateLog()n System.out.println("validatelog");n //age值必须在10-30之间n if(age<10||age>30)n n addFieldError("age", "age must be from 10 to 30!");n n n struts.xmln n n n /hello.jspn n /validateLogin.jspn n n 我的问题是action标签里面没有写method属性,为什么会执行log()方法呢?n 我以为就直接执行execute()方法就完了
struts2与spring集成时,Action成员bean自动注入
[size=medium] 在struts2与spring集成时,如何让Action成员bean自动注入,但当然完全可以通过注解的方式,但是常用的还是在struts.xml文件中,配置[/size] [code=&quot;java&quot;][/code] [size=medium] 这句代码的意思就是spring 托管 意思是struts2的action由spirng负责实例化。 st...
Spring三种实现自动代理
Spring三种实现自动代理 1.基于bean配置名规则的自动代理创建器:允许为一组特定配置名的bean自动创建代理实例的代理创建器,实现类为:BeanNameAutoProxyCreator 2.基于Advisor匹配机制的自动代理创建器,实现类为:DefaultAdvisorAutoProxyCreator 3.基于bean中的AspectJ注解标签的自动代理创建器 第
Spring - AOP之传统自动代理
一、AOP之传统自动代理——基于Bean名称的自动代理 package com.imooc.aop.demo5; public class CustomerDao { public void find(){ System.out.println(&quot;查询客户...&quot;); } public void save(){ System...
spring aop 自动代理机制
我们一直使用ProxyFactoryBean来显式的创建AOP代理。但是在很多场合,这种方式将会使编写配置文件的工作量大大增加;由于要从ProxyFactoryBean获得代理对象,也会使应用和Spring之间的耦合度增加。下面介绍使用Spring提供的自动代理机制来解决这类问题。 1、使用BeanNameAutoProxyCreator Spring提供的BeanNa...
spring 自动代理事务的问题
小弟遇到个问题,请各位大虾指教,在此先谢过了!rnrn用spring2.5 + struts2 + hibernate3.0做一个项目,在Applicationcontext.xml中配置了自动代理事务后遇到如下问题:rnrnrntomcat服务器rnrn严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerrnorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'datasource' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.AbstractMethodError: org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator.determineConstructor(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/reflect/Constructor;rnCaused by: java.lang.AbstractMethodError: org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator.determineConstructor(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/reflect/Constructor;rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:743)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:716)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:387)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:287)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)rn at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:244)rn at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:187)rn at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)rn at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3934)rn at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429)rn at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)rn at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)rn at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)rn at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:987)rn at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:909)rn at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:495)rn at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1206)rn at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:314)rn at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)rn at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)rn at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)rn at org.apache.catalina.core.StandardService.start(StandardService.java:516)rn at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)rn at org.apache.catalina.startup.Catalina.start(Catalina.java:583)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)rn at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)rn2010-1-21 15:57:35 org.apache.catalina.core.StandardContext startrn严重: Error listenerStartrn--------------------------------------------------------------------------------------------rnapplicationcontext如下:rnrn rn rn rn rn rn rn rn rn rn oracle.jdbc.driver.OracleDriverrn rn rn jdbc:oracle:thin:@localhost:1521/myServerrn rn rn testrn rn rn testrn rn rn rnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn org.hibernate.dialect.Oracle9Dialectrn rn rn rn rn rn com/pojo/ServerInfo.hbm.xmlrn rn rn rn rn rn rn rn rnrnrn rn rn rn rn PROPAGATION_REQUIREDrn rn rn rnrnrn rnrn rnrn rn *Servicern rnrn rnrn rn rn transactionInterceptorrnrn rn rn rnrn----------------------------------------------------------------------------rnrn不知道是不是少了什么配置,总之找了好久也没有解决,不吝赐教!
Spring AOP 自动创建代理
目录   1、概述 2、实现类介绍 3、BeanNameAutoProxyCreator的使用 4、DefaultAdvisorAutoProxyCreator 1、概述 在学习切面的时候,都是通过ProxyFactoryBean创建织入切面的代理,每个需要被代理Bean都需要使用一个ProxyFactoryBean进行配置,很是麻烦。Spring为我们提供了自动代理机制,Sprin...
Spring Aop自动创建代理
1.介绍 在Bean生命周期过长中调用BeanPostProcessor,将对象进行包装,生成代理对象。 2.举例 public class LogMethodInterceptor implements MethodInterceptor { @Override public Object invoke(MethodInvocation invocation...
Spring实现自动代理Demo
Spring实现自动代理Demo,BeanNameAutoProxyCreator的运用,学习参考原理
spring中AOP的自动代理
DefaultAdvisorAutoProxyCreator 这种配置方式与BeanNameAutoProxyCreator自动创建代理的方式非常相似,都是使用bean后处理器为目标bean创建代理,区别是前者使用事务拦截器创建代理 ,后者需要使用Advisor创建事务代理 。 事实上,采用DefaultAdvisorAutoProxyCreator的事务代理配置方式更加简洁,这个代理生...
Spring学习-20:Spring的AOP:自动代理
前面所讲的代理,都必须手动配置。下面来介绍一下自动代理。 前面的案例中,每个代理都是通过ProxyFactoryBean织入切面代理,在实际开发中,非常多的Bean每个都配置ProxyFactoryBean开发维护量巨大。自动创建代理(*****基于后处理Bean.在Bean创建的过程中完成的增强.生成Bean就是代理。) (1)BeanNameAutoProxyCreator根据Bean
Struts2 action result ->action?
[code=XML]rnrn zzz.actionrnrn[/code]rn这样不可以?
spring无法代理struts的action的问题
一个使用struts和springjavamail发送邮件的方法。rnrn报的错是:rnorg.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from file [D:\Develop\apache-tomcat-5.5.23\bin\WebRoot\WEB-INF\ComplexMailSender.xml]; nested exception is java.io.FileNotFoundException: WebRoot\WEB-INF\ComplexMailSender.xml (系统找不到指定的路径。)rnjava.io.FileNotFoundException: WebRoot\WEB-INF\ComplexMailSender.xml (系统找不到指定的路径。)rnrn调用的文件是:rnpublic class SendMailAction extends MappingDispatchAction rn rn public ActionForward send(ActionMapping mapping, ActionForm form,rn HttpServletRequest request, HttpServletResponse response) rn rn DynaActionForm sendMailForm = (DynaActionForm) form;rn AbstractMessageSender ams = new AbstractMessageSender();rn ams.setSubject(sendMailForm.getString("title"));rn ams.setTo(sendMailForm.getString("to"));rn ams.setContent(sendMailForm.getString("content"));rn tryrn rn ComplexMessageSender.main();rn rn catch(Exception e)rn rn e.printStackTrace();rn rn return mapping.findForward("test.jsp");rn rnrnrn发送的文件是:rnpublic class ComplexMessageSender extends AbstractMessageSender rn rn rn rn public void sendMessage() throws MessagingExceptionrn rn sender.send(new MessagePreparator());rn rnrn /**rn * @param argsrn */rn public static void main() throws Exception rn // TODO Auto-generated method stub rn ApplicationContext ctx = new FileSystemXmlApplicationContext(new String[]"/WebRoot/WEB-INF/ComplexMailSender.xml");rn ComplexMessageSender sender = (ComplexMessageSender)ctx.getBean("messageSender");rn AbstractMessageSender ams = new AbstractMessageSender();rn sender.setSubject(ams.getSubject());rn sender.setTo(ams.getTo());rn System.out.println("-----------发送邮件!---------");rn tryrn rn sender.sendMessage();rn catch (MailException me)rn rn me.printStackTrace();rn rn System.out.println("-----------发送成功!---------");rn rn private class MessagePreparator implements MimeMessagePreparatorrn rn public void prepare(MimeMessage msg) throws Exceptionrn rn AbstractMessageSender ams = new AbstractMessageSender();rn //ApplicationContext ctx = new FileSystemXmlApplicationContext(new String[]"/WebRoot/WEB-INF/applicationContext.xml");rn //ComplexMessageSender sender = (ComplexMessageSender)ctx.getBean("messageSender");rn rn msg.addFrom(InternetAddress.parse(from));rn msg.addRecipients(Message.RecipientType.TO, InternetAddress.parse(to));rn msg.setSubject(subject);rn rn rn rn MimeMultipart ma = new MimeMultipart("alternative");rn msg.setContent(ma);rn rn BodyPart plainText = new MimeBodyPart();rn //plainText.setText("This is the plain text version of the mail.");rn plainText.setText(ams.getContent());rn ma.addBodyPart(plainText);rn rn BodyPart related = new MimeBodyPart();rn MimeMultipart mr = new MimeMultipart("related");rn related.setContent(mr);rn ma.addBodyPart(related);rn rn /*BodyPart html = new MimeBodyPart();rn html.setContent(" This is the HTML version of the mail." +rn "", "text/html");rn mr.addBodyPart(html);*/rn BodyPart img = new MimeBodyPart();rn img.setHeader("Content-ID", "0001");rn img.setDisposition("inline");rn img.setDataHandler(new DataHandler(new FileDataSource("./WebRoot/image/girl.jpg")));rn mr.addBodyPart(img);rn rn rnrnrnrn请原因是什么,是不能用FileSystemXmlApplicationContext,还是不能在其他的文件总调用main方法?
struts2 action创建 Thread什么时候会销毁
我想新开一个线程发送邮件,不知道邮件发送成功后,这个线程还会存在吗rn [code="java"]rn new Thread(new Runnable() rn @Overridern public void run() rn try rn 发送邮件rn rn catch (Exception e) rn e.printStackTrace();rn rn rn ).start();rn[/code]
Struts2 in action(struts2实战)
Struts2作为javaweb开发的三大框架之一,很有必要了解其使用以及原理
Struts2 In Action(Struts2 实战)
本书结合实例介绍了Struts 2框架,主要内容包括Action、Result、Interceptor等框架组件,基于注解的配置选项等新特征,Struts 2插件 FreeMarker,如何从Struts 1和WebWork 2迁移到Struts 2,Ajax标签、Spring框架集成等新特性。本书适合各层次Java开发人员阅读和参考
spring的action代理集成struts 多个action是时候出错
错误提示:rnrn严重: Servlet.service() for servlet action threw exceptionrnorg.springframework.beans.factory.BeanCreationException: Error creating bean with name '/display' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.InvalidPropertyException: Invalid property 'teacherInfoService' of bean class [com.teacherInfo.struts.action.DisplayAction]: No property 'teacherInfoService' foundrn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:478)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)rn at java.security.AccessController.doPrivileged(Native Method)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:283)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:168)rn at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:885)rn at org.springframework.web.struts.DelegatingRequestProcessor.getDelegateAction(DelegatingRequestProcessor.java:176)rn at org.springframework.web.struts.DelegatingRequestProcessor.processActionCreate(DelegatingRequestProcessor.java:154)rn at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:221)rn at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)rn at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)rn at java.lang.Thread.run(Unknown Source)rnCaused by: org.springframework.beans.InvalidPropertyException: Invalid property 'teacherInfoService' of bean class [com.teacherInfo.struts.action.DisplayAction]: No property 'teacherInfoService' foundrn at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:382)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1287)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1248)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1008)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:470)rn ... 26 morernrnstruts-config.xml内容:rnrnrn rn rn rn rn rn rn rn rn rn rn rn rnrn rn rn rn rnrn rn rn rn rn rn rnrnapplicationContext.xml内容:rnrnrn rn rn rn rn rn teacherInfoPojo/TeacherInfo.hbm.xmlrn rn rn rn rn rn org.hibernate.dialect.Oracle9Dialectrn rnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrn说明: DisplayAction是后加上去的,开始只有TeacherInfoAction的时候功能实现没有问题 然后我再struts-config.xml加上DisplayAction,在applicationContext.xml中加上bean 其他的地方没有改动 出现上述错误 高手给看看 急~
struts2 in Action
如果你想自学struts2,此文档是很好的自学宝典,经典struts2 in Action,能帮你建立整体的struts2思想,你还在犹豫什么
Struts2 in Action
Struts2 in Action英文版和struts2 in Action中文版(也叫Struts2实战)
struts2 in action
这本权威的struts的书就不用介绍了吧?反正网上评价很不错!
Struts2 In Action
struts2 in Action完整版,购买原版英文书后获得电子版本,大家共享
Struts2 in action
Struts2 in action 中文版
struts2 action
刚刚接触struts2,看了一点例子,有的程序并没有用到.action,这样的程序属于与用到.action有什么本质的区别吗?
相关热词 c# 线程结束时执行 c# kb mb 图片 c# 替换第几位字符 c#项目决定成败 c# 与matlab c# xml缩进 c#传感器基础 c#操作wps c# md5使用方法 c# 引用父窗口的组件