@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
// Note that we want to point to the Application boot class that was originally implemented in main.Return builder.sources (Application.class);}

Anomaly location

In other words, Tomcat was wrong when loading Filter. Check my Filter, I found the following dependency

@Resource(name = "someone")
private SomeObject someone;

The specific classes are hidden here, but SomeObject has the following characteristics.

1.He is a dependency on Spring

2.His specific value is dependent on the database

Question 1

Troubleshooting is always a problem of startup sequence, but it’s not very specific. Review the loading sequence first

listener–>filter–>sevlet–>spring

Because my filter relies on objects in spring, in fact, filter will load filter exceptions during loading.

Question 2

Use@ResourceAnnotation, this annotation is javax standard, in fact not only spring will use it, even Tomcat will use it. So Tomcat will try to load the resource someone when it starts. And because someone actually depends on the database,Only to appearjavax.naming.NamingException: Cannot create resource instanceThis exception.

Terms of settlement

Add Filter in other ways

First, Filter is no longer used@WebFilterAnnotation@ComponentAnnotate, turn this class into a component of Spring, and postpone its loading.

@Component
/*@WebFilter("/*")*/
public class Filter001
……

Do not use@Resourceannotation

Because Tomcat also recognizes@Resource，So we don’t use it instead of using it to use it.@Autowiredand@QualifierThese two annotations.