问题根源都是因为没有被spring 接管到

感谢这位博主

问题一     Springboot整合Web Controller未生效 访问全是404

解决办法一:
启动类上加 @ComponentScan("com.example.controller")

解决办法二:
@SpringBootApplication 后面加 (scanBasePackages = "com.example.controller")

问题二     Springboot里的整合spring security 时config无法生效

解决办法一:
启动类上加 @ComponentScan("com.example.config")

解决办法二:
@SpringBootApplication 后面加 (scanBasePackages = "com.example.config")

其他包类如果有未生效,操作同理

简写:

alt

详细代码如下
package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

/**
 * @author CodeHaywire
 */
@ComponentScan({"com.example.controller", "com.example.config"})
@SpringBootApplication
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @author CodeHaywire
 */
@SpringBootApplication(scanBasePackages = {"com.example.controller","com.example.config"})
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}