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;  
    }  

  

 

posted on 2018-03-14 12:30  superficial。  阅读(154)  评论(0编辑  收藏  举报

导航