精华内容
下载资源
问答
  • Design Pattern - Template Method(C#)

    万次阅读 多人点赞 2019-02-26 20:29:04
    分享一个大牛的人工智能教程。零基础!通俗易懂!风趣幽默!希望你也加入到人工智能的队伍中来!... Definition Define the skeleton of an algorithm in an operation, deferring some ... Template Method lets su...

    分享一个大牛的人工智能教程。零基础!通俗易懂!风趣幽默!希望你也加入到人工智能的队伍中来!请点击http://www.captainbed.net 

    Definition

    Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.

    Participants

    The classes and/or objects participating in this pattern are:

    • AbstractClass (DataObject)
      • Defines abstract primitive operations that concrete subclasses define to implement steps of an algorithm
      • Implements a template method defining the skeleton of an algorithm. The template method calls primitive operations as well as operations defined in AbstractClass or those of other objects
    • ConcreteClass (CustomerDataObject)
      • Implements the primitive operations or carry out subclass-specific steps of the algorithm

    Sample Code in C#

    This structural code demonstrates the Template method which provides a skeleton calling sequence of methods. One or more steps can be deferred to subclasses which implement these steps without changing the overall calling sequence.

    /*
     * Structural Template Method Pattern.
     */
    
    using System;
    
    namespace TemplateMethod.Sample
    {
        /// <summary>
        /// Startup class for sample Template Method design pattern.
        /// </summary>
        public class Program
        {
            /// <summary>
            /// Entry point into console application.
            /// </summary>
            public static void Main()
            {
                AbstractClass aA = new ConcreteClassA();
                aA.TemplateMethod();
    
                AbstractClass aB = new ConcreteClassB();
                aB.TemplateMethod();
            }
        }
    
        /// <summary>
        /// The 'AbstractClass' abstract class.
        /// </summary>
        public abstract class AbstractClass
        {
            /// <summary>
            /// The primitive operation 1.
            /// </summary>
            public abstract void PrimitiveOperation1();
    
            /// <summary>
            /// The primitive operation 2.
            /// </summary>
            public abstract void PrimitiveOperation2();
    
            /// <summary>
            /// The template method.
            /// </summary>
            public void TemplateMethod()
            {
                PrimitiveOperation1();
                PrimitiveOperation2();
                Console.WriteLine(string.Empty);
            }
        }
    
        /// <summary>
        /// A 'ConcreteClass' class.
        /// </summary>
        public class ConcreteClassA : AbstractClass
        {
            /// <summary>
            /// The primitive operation 1.
            /// </summary>
            public override void PrimitiveOperation1()
            {
                Console.WriteLine("ConcreteClassA.PrimitiveOperation1()");
            }
    
            /// <summary>
            /// The primitive operation 2.
            /// </summary>
            public override void PrimitiveOperation2()
            {
                Console.WriteLine("ConcreteClassA.PrimitiveOperation2()");
            }
        }
    
        /// <summary>
        /// A 'ConcreteClass' class.
        /// </summary>
        public class ConcreteClassB : AbstractClass
        {
            /// <summary>
            /// The primitive operation 1.
            /// </summary>
            public override void PrimitiveOperation1()
            {
                Console.WriteLine("ConcreteClassB.PrimitiveOperation1()");
            }
    
            /// <summary>
            /// The primitive operation 2.
            /// </summary>
            public override void PrimitiveOperation2()
            {
                Console.WriteLine("ConcreteClassB.PrimitiveOperation2()");
            }
        }
    }
    
    // Output:
    /*
    ConcreteClassA.PrimitiveOperation1()
    ConcreteClassA.PrimitiveOperation2()
    
    ConcreteClassB.PrimitiveOperation1()
    ConcreteClassB.PrimitiveOperation2()
    
    
    */

    This real-world code demonstrates a Template method named Run() which provides a skeleton calling sequence of methods. Implementation of these steps are deferred to the CustomerDataObject subclass which implements the Connect, Select, Process, and Disconnect methods.

    /*
     * Real-World Template Method Pattern.
     */
    
    using System;
    using System.Data;
    using System.Data.OleDb;
    
    namespace TemplateMethod.RealWorld
    {
        /// <summary>
        /// Startup class for Real-World Template Method design pattern.
        /// </summary>
        public class Program
        {
            /// <summary>
            /// Entry point into console application.
            /// </summary>
            public static void Main()
            {
                DataAccessObject daoCategories = new Categories();
                daoCategories.Run();
    
                DataAccessObject daoProducts = new Products();
                daoProducts.Run();
            }
        }
    
        /// <summary>
        /// The 'AbstractClass' abstract class.
        /// </summary>
        public abstract class DataAccessObject
        {
            /// <summary>
            /// The connection string.
            /// </summary>
            protected string ConnectionString;
    
            /// <summary>
            /// The data set.
            /// </summary>
            protected DataSet DataSet;
    
            /// <summary>
            /// Connect.
            /// </summary>
            public virtual void Connect()
            {
                // Make sure mdb is available to program.
                ConnectionString = "provider=Microsoft.JET.OLEDB.4.0; data source=..\\..\\db1.mdb";
            }
    
            /// <summary>
            /// Select.
            /// </summary>
            public abstract void Select();
    
            /// <summary>
            /// Process.
            /// </summary>
            public abstract void Process();
    
            /// <summary>
            /// Disconnect.
            /// </summary>
            public virtual void Disconnect()
            {
                ConnectionString = string.Empty;
            }
    
            /// <summary>
            /// The 'Template Method'.
            /// </summary>
            public void Run()
            {
                Connect();
                Select();
                Process();
                Disconnect();
            }
        }
    
        /// <summary>
        /// A 'ConcreteClass' class.
        /// </summary>
        public class Categories : DataAccessObject
        {
            /// <summary>
            /// Select.
            /// </summary>
            public override void Select()
            {
                const string sql = "select CategoryName from Categories";
                OleDbDataAdapter dataAdapter = new OleDbDataAdapter(sql, ConnectionString);
                DataSet = new DataSet();
                dataAdapter.Fill(DataSet, "Categories");
            }
    
            /// <summary>
            /// Process.
            /// </summary>
            public override void Process()
            {
                Console.WriteLine("Categories ------ ");
                DataTable dataTable = DataSet.Tables["Categories"];
                foreach (DataRow row in dataTable.Rows)
                {
                    Console.WriteLine(row["CategoryName"]);
                }
    
                Console.WriteLine();
            }
        }
    
        /// <summary>
        /// A 'ConcreteClass' class.
        /// </summary>
        public class Products : DataAccessObject
        {
            /// <summary>
            /// Select.
            /// </summary>
            public override void Select()
            {
                const string sql = "select ProductName from Products";
                OleDbDataAdapter dataAdapter = new OleDbDataAdapter(sql, ConnectionString);
                DataSet = new DataSet();
                dataAdapter.Fill(DataSet, "Products");
            }
    
            /// <summary>
            /// Process.
            /// </summary>
            public override void Process()
            {
                Console.WriteLine("Products ------ ");
                DataTable dataTable = DataSet.Tables["Products"];
                foreach (DataRow row in dataTable.Rows)
                {
                    Console.WriteLine(row["ProductName"]);
                }
    
                Console.WriteLine();
            }
        }
    }
    
    // Output:
    /*
    
    Categories ------
    Beverages
    Condiments
    Confections
    Dairy Products
    Grains/Cereals
    Meat/Poultry
    Produce
    Seafood
    
    Products ------
    Chai
    Chang
    Aniseed Syrup
    Chef Anton's Cajun Seasoning
    Chef Anton's Gumbo Mix
    Grandma's Boysenberry Spread
    Uncle Bob's Organic Dried Pears
    Northwoods Cranberry Sauce
    Mishi Kobe Niku
    
    
    */

     

    展开全文
  • 文章目录Channel shutdown: channel error; protocol method: #methodChannel shutdown: ... protocol method: #method<channel.close>(rep 1、启动springboot 应用报错 Channel shutdown: channel error; pr...

    【RabbitMq】Channel shutdown: channel error; protocol method: #method<channel.close>(rep


    如果觉得本文对你有帮助,可以一键三连支持,谢谢

    1、启动springboot 应用报错

    Channel shutdown: channel error; protocol method: #method<channel.close>(rep

    2、原因

    当应用启动时,spring 会去检查注册的队列,跟服务器上的队列配置是否一致,如果不一致,则抛出这个错误

    比如你在项目中的配置是

        @Bean(DEAD_LETTER_PROD_CLOSE_ORDER)
        Queue a() {
            Map<String, Object> args = Maps.newHashMap();
            args.put("x-dead-letter-exchange", RabbitMqExchange.ExchangeCenter.DEAD_LETTER_EXCHANGE_CONSUME);
            args.put("x-dead-letter-routing-key", DEAD_LETTER_CONSUME_CLOSE_ORDER);
            args.put("x-message-ttl", 600 * 1000);
    
            return new Queue(DEAD_LETTER_PROD_CLOSE_ORDER, true, false, false, args);
        }
    

    但是服务器上的配置是

    x-message-ttl=1000
    

    则代码配置与现有队列配置不一致,抛出该错误

    3、解决

    方式一、修改项目配置与mq 保持一致

    修改项目配置与MQ一致则可以正常运行


    方式二、删除mq上现有队列
    删除mq 上现有队列,则springboot 自动向mq 服务器注册一个新的队列,也可以解决该问题

    本文地址 https://wretchant.blog.csdn.net/article/details/99976534
    博客地址 https://wretchant.blog.csdn.net/

    展开全文
  • Design Pattern - Factory Method(C#)

    万次阅读 多人点赞 2019-02-02 17:09:35
    This structual code demonstrates the Factory Method offering great flexibility in creating different objects. The abstract class may provide a default object, but each subclass can instantiate an ...

    分享一个大牛的人工智能教程。零基础!通俗易懂!风趣幽默!希望你也加入到人工智能的队伍中来!请点击http://www.captainbed.net 

    Definition

    Define an interface for creating an object, but let sub classes decide which class to instantiate. Factory Method lets a class defer instantiation to sub classes.

    Participants

        The classes and/or objects participating in this pattern are:

    • Product (Page)
      • Defines the interface of objects the factory method creates
    • ConcreteProduct (SkillsPage, EducationPage, ExperiencePage)
      • Implements the Product interface
    • Creator (Document)
      • Declares the factory method, which returns an object of type Product. Creator may also define a default implementation of the factory method that returns a default ConcreteProduct object.
      • May call the factory method to create a Product object.
    • ConcreteCreator (Report, Resume)
      • Overrides the factory method to return an instance of a ConcreteProduct.

    Sample Code in C#


    This structual code demonstrates the Factory Method offering great flexibility in creating different objects. The abstract class may provide a default object, but each subclass can instantiate an extended version of the object.

    /*
     * Structural Factory Method Design Pattern.
     */
    
    namespace FactoryMethod.Sample
    {
        using System;
        using System.Linq;
    
        /// <summary>
        /// Startup class for Structural Factory Method Design Pattern.
        /// </summary>
        internal static class Program
        {
            #region Methods
    
            /// <summary>
            /// Entry point into console application.
            /// </summary>
            private static void Main()
            {
                // An array of creators.
                var creators = new Creator[2];
                creators[0] = new ConcreteCreatorA();
                creators[1] = new ConcreteCreatorB();
    
                // Iterate over creators and create products.
                foreach (Product product in creators.Select(creator => creator.FactoryMethod()))
                {
                    Console.WriteLine("Created {0}", product.GetType().Name);
                }
            }
    
            #endregion
        }
    
        /// <summary>
        /// The 'Product' abstract class.
        /// </summary>
        internal abstract class Product
        {
        }
    
        /// <summary>
        /// A 'ConcreteProduct' class.
        /// </summary>
        internal class ConcreteProductA : Product
        {
        }
    
        /// <summary>
        /// A 'ConcreteProduct' class.
        /// </summary>
        internal class ConcreteProductB : Product
        {
        }
    
        /// <summary>
        /// The 'Creator' abstract class
        /// </summary>
        internal abstract class Creator
        {
            #region Public Methods and Operators
    
            /// <summary>
            /// The factory method.
            /// </summary>
            /// <returns>
            /// The <see cref="Product"/>.
            /// </returns>
            public abstract Product FactoryMethod();
    
            #endregion
        }
    
        /// <summary>
        /// A 'ConcreteCreator' class.
        /// </summary>
        internal class ConcreteCreatorA : Creator
        {
            #region Public Methods and Operators
    
            /// <summary>
            /// The factory method.
            /// </summary>
            /// <returns>
            /// The <see cref="Product"/>.
            /// </returns>
            public override Product FactoryMethod()
            {
                return new ConcreteProductA();
            }
    
            #endregion
        }
    
        /// <summary>
        /// A 'ConcreteCreator' class.
        /// </summary>
        internal class ConcreteCreatorB : Creator
        {
            #region Public Methods and Operators
    
            /// <summary>
            /// The factory method.
            /// </summary>
            /// <returns>
            /// The <see cref="Product"/>.
            /// </returns>
            public override Product FactoryMethod()
            {
                return new ConcreteProductB();
            }
    
            #endregion
        }
    }
    
    // Output:
    /*
    Created ConcreteProductA
    Created ConcreteProductB
    
    */

    This real-world code demonstrates the Factory Method offering flexibility in creating different documents. The derived Document classes Report and Resume instantiate extended versions of the Document class. Here, the Factory Method is called in the constructor of the Document base class.

    /*
     * Real-World Factory Method Design Pattern.
     */
    
    namespace FactoryMethod.RealWorld
    {
        using System;
        using System.Collections.Generic;
    
        /// <summary>
        /// Startup class for Real-World Factory Method Design Pattern.
        /// </summary>
        internal static class Program
        {
            #region Methods
    
            /// <summary>
            /// Entry point into console application.
            /// </summary>
            private static void Main()
            {
                // Note: constructors call Factory Method.
                var documents = new Document[2];
                documents[0] = new Resume();
                documents[1] = new Report();
    
                // Display document pages.
                foreach (Document document in documents)
                {
                    Console.WriteLine("\n" + document.GetType().Name + "--");
                    foreach (Page page in document.Pages)
                    {
                        Console.WriteLine(" " + page.GetType().Name);
                    }
                }
            }
    
            #endregion
        }
    
        /// <summary>
        /// The 'Product' abstract class.
        /// </summary>
        internal abstract class Page
        {
        }
    
        /// <summary>
        /// A 'ConcreteProduct' class.
        /// </summary>
        internal class SkillsPage : Page
        {
        }
    
        /// <summary>
        /// A 'ConcreteProduct' class.
        /// </summary>
        internal class EducationPage : Page
        {
        }
    
        /// <summary>
        /// A 'ConcreteProduct' class.
        /// </summary>
        internal class ExperiencePage : Page
        {
        }
    
        /// <summary>
        /// A 'ConcreteProduct' class.
        /// </summary>
        internal class IntroductionPage : Page
        {
        }
    
        /// <summary>
        /// A 'ConcreteProduct' class.
        /// </summary>
        internal class ResultsPage : Page
        {
        }
    
        /// <summary>
        /// A 'ConcreteProduct' class.
        /// </summary>
        internal class ConclusionPage : Page
        {
        }
    
        /// <summary>
        /// A 'ConcreteProduct' class.
        /// </summary>
        internal class SummaryPage : Page
        {
        }
    
        /// <summary>
        /// A 'ConcreteProduct' class.
        /// </summary>
        internal class BibliographyPage : Page
        {
        }
    
        /// <summary>
        /// The 'Creator' abstract class.
        /// </summary>
        internal abstract class Document
        {
            #region Constructors and Destructors
    
            /// <summary>
            /// Initializes a new instance of the <see cref="Document"/> class.
            /// </summary>
            protected Document()
            {
                CreatePages();
            }
    
            #endregion
    
            #region Public Properties
    
            /// <summary>
            /// Gets the pages.
            /// </summary>
            public List<Page> Pages { get; } = new List<Page>();
    
            #endregion
    
            // Factory Method
            #region Public Methods and Operators
    
            /// <summary>
            /// Create pages.
            /// </summary>
            protected abstract void CreatePages();
    
            #endregion
        }
    
        /// <summary>
        /// A 'ConcreteCreator' class.
        /// </summary>
        internal class Resume : Document
        {
            #region Public Methods and Operators
    
            /// <summary>
            /// Create pages.
            /// </summary>
            protected override void CreatePages()
            {
                Pages.Add(new SkillsPage());
                Pages.Add(new EducationPage());
                Pages.Add(new ExperiencePage());
            }
    
            #endregion
        }
    
        /// <summary>
        /// A 'ConcreteCreator' class.
        /// </summary>
        internal class Report : Document
        {
            #region Public Methods and Operators
    
            /// <summary>
            /// Create pages.
            /// </summary>
            protected override void CreatePages()
            {
                Pages.Add(new IntroductionPage());
                Pages.Add(new ResultsPage());
                Pages.Add(new ConclusionPage());
                Pages.Add(new SummaryPage());
                Pages.Add(new BibliographyPage());
            }
    
            #endregion
        }
    }
    
    // Output:
    /*
    
    Resume--
     SkillsPage
     EducationPage
     ExperiencePage
    
    Report--
     IntroductionPage
     ResultsPage
     ConclusionPage
     SummaryPage
     BibliographyPage
    
    */

     

    展开全文
  • java代码中init method和destroy method的三种使用方式

    万次阅读 多人点赞 2016-12-12 11:15:44
    在java的实际开发过程中,我们可能常常需要使用到init method和destroy method,比如初始化一个对象(bean)后立即初始化(加载)一些数据,在销毁一个对象之前进行垃圾回收等等。 周末对这两个方法进行了一点学习...

    在java的实际开发过程中,我们可能常常需要使用到init method和destroy method,比如初始化一个对象(bean)后立即初始化(加载)一些数据,在销毁一个对象之前进行垃圾回收等等。
    周末对这两个方法进行了一点学习和整理,倒也不是专门为了这两个方法,而是在巩固spring相关知识的时候提到了,然后感觉自己并不是很熟悉这个,便好好的了解一下。
    根据特意的去了解后,发现实际上可以有三种方式来实现init method和destroy method。
    要用这两个方法,自然先要知道这两个方法究竟是干嘛用的。而从字面意思就很容易理解,一个是加载,一个是销毁。
    下边就正式代码演示三种创建方式:
    一、@Bean注解方式:
    首先要创建一个至少拥有两个方法的类,一个方法充当init method,另一个充当destroy method。

    package springTest2;
    public class Test1 {
    	public void init() {
    		System.out.println("this is init method1");
    	}
    	public Test1() {
    		super();
    		System.out.println("构造函数1");
    	}
    	public void destroy() {
    		System.out.println("this is destroy method1");
    	}
    }
    

    这里很显然只是一个普通的java类,拥有一个无参构造和另外两个方法。
    需要注意的是,这里的init和destroy两个方法名实际上是可以随意取得,不叫这个也没有问题,只不过算是一种约定俗称,一般都是这样叫。
    另外我们也知道,这个构造方法也是可以不要的,因为会隐式的自动创建,但是为了更清楚的看到init和destroy是什么时候执行,我们就显示的写出来。
    创建好了这个类,我们就可以使用@Bean注解的方式指定两个方法,以让他们生效。

    package springTest2;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.context.annotation.Configuration;
    @Configuration
    @ComponentScan("springTest2")
    public class ConfigTest {
    	@Bean(initMethod = "init", destroyMethod = "destroy")
    	Test1 test1() {
    		return new Test1();
    	}
    }
    

    这里边的@Configguration注解是告诉spring这个类是一个配置类,相当于我们的xml文件,@ComponentScan则是指定需要spring来扫描的包,相当于xml中的context:component-scan属性。
    而@Bean后边的initMethod和destroyMethod就是在声明这是一个baen的同时指定了init和destroy方法,方法名从功能实现上来说可以随意。
    到这里我们就已经用第一种方式写好了,为了验证成功与否,再写一个main方法验证一下:

    package springTest2;
    import org.springframework.context.annotation.AnnotationConfigApplicationContext;
    public class MainTest {
    	public static void main(String[] args) {
    		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConfigTest.class);
                    System.out.println("#################################");
    		context.close();
    	}
    }
    

    运行之后结果如图:
    这里写图片描述
    根据打印顺序可以看到,首先是构造函数,也就是创建了bean,紧接着执行了init,然后再context.close要销毁bean之前又执行了destroy。

    二、JSR-250注解的方式(需要导入jsr250-api的jar包):
    首先依然是创建一个拥有构造方法在内的三个方法的java类:

    package springTest2;
    import javax.annotation.PostConstruct;
    import javax.annotation.PreDestroy;
    public class Test2 {
    	@PostConstruct
    	public void init() {
    		System.out.println("this is init method2");
    	}
    	public Test2() {
    		super();
    		System.out.println("构造函数2");
    	}
    	@PreDestroy
    	public void destroy() {
    		System.out.println("this is destroy method2");
    	}
    }
    

    很显然,这里和上一个类不同的是,在init和destroy方法上加入了两个注解,@PostConstruct和上边@Bean后的initMethod相同,而@PreDestroy则是和destroyMethod做用相同。
    既然这里有了区别,已经指定了init method和destroy method,那么后边声明bean的时候自然也会有不同,也就不需要再指定一遍:

    package springTest2;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.context.annotation.Configuration;
    @Configuration
    @ComponentScan("springTest2")
    public class ConfigTest {
    	@Bean
    	Test2 test2() {
    		return new Test2();
    	}
    }
    

    所以,如上代码中只需要简单的声明这是一个bean就可以了,类上边的两个注解和上一个例子中的意思相同。
    再测试一下:

    package springTest2;
    import org.springframework.context.annotation.AnnotationConfigApplicationContext;
    public class MainTest {
    	public static void main(String[] args) {
    		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConfigTest.class);
                    System.out.println("#################################");
    		context.close();
    	}
    }
    

    结果如下:
    这里写图片描述

    三、xml配置的方式:
    这种方式实际上是和第一种对应的,只不过细节上略有改变而已,首先,创建的java类完全一样:

    package springTest2;
    public class Test3 {
    	public void init() {
    		System.out.println("this is init method3");
    	}
    	public Test3() {
    		super();
    		System.out.println("构造函数3");
    	}
    	public void destroy() {
    		System.out.println("this is destroy method3");
    	}
    	public void test() {
    		System.out.println("testttttttt");
    	}
    }
    

    不同的地方就在于,第一个例子中是使用注解告诉spring这个类相当于一个配置文件,而这里则是实实在在的配置文件spring.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"  
        xsi:schemaLocation="http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans.xsd">  
    
    <bean id="initOrDestroyTest" class="springTest2.Test3" init-method="init" destroy-method="destroy">
    </bean>
    </beans>
    

    这个配置大概也能算是spring.xml中最简单的一个配置了吧,除开必要的文件头,就只有一个bean,而且bean里边也只有id,calss和init以及destroy方法。
    因为简单,所以一目了然,id只是为了其他地方引用,class是指定这个bean对应的类,而后边两个属性则和用@Bean声明时一模一样。
    因为这里声明bean和指定两个方法是用的xml配置,因此在测试的时候也就需要稍微有一点点改变:

    package springTest2;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    public class MainTest {
    	public static void main(String[] args) {
    		ClassPathXmlApplicationContext context1 = new ClassPathXmlApplicationContext("spring.xml");
    		System.out.println("#################################");
    		context1.close();
    	}
    }
    

    区别在于这里直接加载了配置文件,而不是java类,使用的是ClassPathxXmlApplicationContext而不是AnnotationConfigApplicationContext。
    结果如下:
    这里写图片描述

    这里需要说明的一点是,在实际的web应用使用时,可以在web.xml中使用类似下边的配置来加载bean,实现init method:

    <servlet-name>dispatcher</servlet-name>  
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
        <init-param>  
          <param-name>contextConfigLocation</param-name>  
          <param-value>classpath:spring.xml</param-value>  
        </init-param>  
        <load-on-startup>1</load-on-startup>  
      </servlet>  
      <servlet-mapping>  
        <servlet-name>dispatcher</servlet-name>  
        <url-pattern>/</url-pattern>  
      </servlet-mapping> 
    

    然后启动tomcat结果如下:
    这里写图片描述
    这里边没有调用destroy method,原因是spring本身代码就需要我们手动调用销毁bean的方法,像前边的几个例子中的context.close就是。
    如果不手动调用这个方法,bean就不会被销毁,也就不会去调用destroy method,这也就是为何这里在web.xml中配置后,启动tomcat 只打印了构造函数和init方法中的内容。

    例子都是很简单的,而通过简单的例子对比可能能更进一步理解相关的知识,理解了才能在实际应用中更好的进行选择和集成。

    展开全文
  • java反射之Method的invoke方法实现

    万次阅读 多人点赞 2018-07-29 00:31:48
    在框架中经常会会用到method.invoke()方法,用来执行某个的对象的目标方法。以前写代码用到反射时,总是获取先获取Method,然后传入对应的Class实例对象执行方法。然而前段时间研究invoke方法时,发现invoke方法居然...
  • Android开发遇到的第一个问题:Failed to resolve:com.android.support:appcompat-v7,Method does not override method from its superclass 解决办法:...
  • Method has too many Body parameters的处理办法

    万次阅读 多人点赞 2018-06-07 11:42:58
    SpringCloud Feign报错:Method has too many Body parameters 1、feign多参数问题 1.1GET方式 错误写法 @RequestMapping(value="/test", method=RequestMethod.GET) Model test(final String name, final int...
  • runtime Method

    千次阅读 2016-01-12 17:49:09
    原文出自:标哥的技术博客 前言本篇文章只讲Method的特性及相关方法,不讲Method ...Method类型Method类型是一个objc_method结构体指针,而结构体objc_method有三个成员:/// An opaque type that represents a meth
  • 关于这个问题网上的资料很少,估计是很少人遇到...java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens at org.apache.coyote.http11.InternalAprInpu
  • 如果我们想在初始化某个bean对象时自定义自己的init-method和destroy-method方法,我们可以使用通过Java配置文件方式注入要自定义自己init-method和destroy方法的bean,然后通过注解指定init-method和destroy-method...
  • 关于SpringBoot应用挂了很久之后,会发生Invalid character found in method name. HTTP method names must be tokens的问题。 解决方案 据说是tomcat 的设置问题,如果出现相关情况,可以设置一下application....
  • Method详解

    万次阅读 2016-10-25 20:59:44
    java反射的Method 提供关于类或接口上单独某个方法(以及如何访问该方法)的信息。
  • Method test should have no parameters ... java.lang.Exception: Method test should have no parameters ... 报错如上,用Test 跑单元测试是要求方法不能有参数和返回类型的,改下测试的方法就行了。...
  • 微信小程序:Component "页面路径" does not have a method " 方法名" to handle event "tap".
  • Java Method

    千次阅读 2020-03-04 18:10:13
    本文介绍了 Java 中 Method 类的相关内容。。。
  • org.apache.ibatis.binding.BindingException: Mapper method 'share.pmc.modular.ed.mapper.DeviceMapper.uoStatus attempted to return null from a method with a primitive return type (int). 映射语句错误 我...
  • SpringCloud Feign Method remove not annotated with HTTP method type 异常解决办法SpringCloud Feign Method remove not annotated with HTTP method type 异常解决办法原因,及解决办法。 SpringCloud Feign ...
  • Pycharm中,解决 RuntimeError: implement_array_function method already has a docstring. numpy,pandas,matplotlib版本不兼容。
  • 解决 Invalid character found in method name. HTTP method names must be tokens 原因: ssl证书到期了 postman请求返回截图:
  • Spring 的 init-method 和 destory-method

    千次阅读 2018-05-15 23:50:46
    关于在spring 容器初始化 bean 和销毁前所做的操作定义方式有三种:第一种:通过@PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作第二种是:通过 在xml中定义init-method 和 destory-method...
  • 什么是HandlerMethod

    万次阅读 2019-10-10 21:40:13
    Spring MVC : 概念模型 HandlerMethod ...
  • Invalid character found in method name. HTTP method names must be tokens异常 异常描述: java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens ...
  • 背景 在使用SpringbootFeign调用的时候,会出现以下报错 org.springframework.web.... at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.handleNoMatch(RequestMapping..
  • No such method

    千次阅读 2019-06-26 00:45:24
    NoSuchMethod一个常见的原因是编译问题。通常可能是同名的类或者方法被覆盖掉。
  • 文章目录现象分析密码重置...现象 ...report:  Method Not Allowed The method is not allowed for the requested URL. 分析 密码重置流程如下: 1)登录界面放置重置密码超链接,指向/auth/start_resetpwd 2)/...
  • 07--lookup-method和replace-method注入

    千次阅读 2018-11-01 15:24:18
    即我们通常所说的lookup-method注入。 替换方法注入:可以实现方法主体或返回结果的替换,即我们通常所说的replaced-method注入。 1. lookup-method注入 单例模式的bean只会被创建一次,IoC容器会缓存该bean实例以...
  • Method not found

    千次阅读 2019-05-24 02:16:02
    javax.el.MethodNotFoundException: Method not found: class com.kgc.pojo.News.author() 这个怎么解决
  • java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:...
  • org.apache.ibatis.binding.BindingException: Mapper method attempted to return null from a method with a primitive return type (int). 错误写法: <select id="updatePayoffStatusById" result...
  • invalid method declaration

    千次阅读 2018-07-11 23:46:42
    invalid method declaration; return type required public showMyLove() { ^ 1 error方法声明无效; 需要返回类型public showMyLove(){

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 594,397
精华内容 237,758
关键字:

method