zoukankan      html  css  js  c++  java
  • springboot

    Spring -boot 的默认端口为8080 ,要修改端口号可以修改src/main/resources下的properties文件   server.context-path=/helloboot (修改默认路径为httplocahost8081/helloboot

     server.port=8081  (修改端口号为8081)

    @component注解可以使配置类直接扫描到spring容器中,配置类上需要加@componentscan注解

    @springbootapplication configurationcomponentscan

    @springbootapplication 所在的类上面添加@mapperscan注解可以扫描 mapper所在的包

    错误:There is already 'baseController' bean method spring

    这个问题是因为方法的路由重复了!

    错误:Whitelabel error page

    这个错误是因为 springboot所有的包必须要跟程序入口类在一个包下(同级)

    1、自定义事件,一般是继承ApplicationEvent抽象类

    2、定义事件监听器,一般是实现ApplicationListener接口

    3、启动时要把监听器添加到spring容器中  例如:apringapplication.addlistener(new Applicationlistener())

       或者可以在监听器的类上边添加@component注解

    4、发布事件,实用applicationcontext.publishevent发布事件

    例子:app.addListeners(new MyApplicationListener());//将监听器添加到spring

    ConfigurableApplicationContext context = app.run(args);

    context.publishEvent(new MyapplicationEvent(new Object()));//发布事件

    springboot中使用jsp,需要另外加入tomcat-embed-jasper的依赖,然后,需要在配置文件中,配置如下的两个配置项: spring.mvc.view.prefix=/web-inf/jsp

                                       Spring.mvc.view.suffix=.jsp

    Properties文件中需要的数据库的数据 url username password 其中url的数据不能加双引号

    spring boot 修改DispatcherServlet默认拦截路径:

    /**  
         * 修改DispatcherServlet默认配置  
         *  
         * @param dispatcherServlet  
         * @return  
         * @author SHANHY  
         * @create  2016年1月6日  
         */  
        @Bean  
        public ServletRegistrationBean dispatcherRegistration(DispatcherServlet dispatcherServlet) {  
            ServletRegistrationBean registration = new ServletRegistrationBean(dispatcherServlet);  
            registration.getUrlMappings().clear();  
            registration.addUrlMappings("*.do");  
            registration.addUrlMappings("*.json");  
            return registration;  
        }  
    

      

  • 相关阅读:
    C#在winform中操作数据库,实现数据增删改查
    未开启Hyper-V,却提示VMware Workstation与Hyper-V不兼容。
    winform实例(5)-截屏工具+保存
    winform实例(4)-播放器(wmp)
    winform实例(3)-利用摄像头进行拍照
    winform实例(2)-简单浏览器
    winform实例(1)-简单记事本
    C#异常处理
    百度文库下载破解
    学习小技能-封装字段
  • 原文地址:https://www.cnblogs.com/gaofangquan/p/8566820.html
Copyright © 2011-2022 走看看