The pit I stepped on when I learned Java in those years

Posted by Fergusfer on Wed, 04 Mar 2020 10:51:00 +0100

All the way to learn Java is like stepping on a hole. Come and let's count my blood and tears over the years

Rookie stage, spend almost every day on thunder...

First: the database table field cannot use sql field, and a 500 error will be reported. For example, the order will report an error when select ing.

Second: when using int type for query operation, the Controller layer should write Integer type, otherwise it will report ""

Request processing failed; nested exception is java.lang.IllegalStateException: Optional int parameter 'page' is present but cannot be translated

into a null value due to being declared as a primitive type. Consider declaring it as object wrapper for the corresponding primitive type

The solution is as follows:

Third: in the generate configuration file, there is a problem in the database table configuration, and @ autowired will report an error that Mapper cannot be found:

Ad locum:

Fourth: Spring Cloud configures Hystrix fuse service.


@SpringBootApplication(exclude={DataSourceAutoConfiguration.class},scanBasePackages= {"com.lero.springCloud.shoppingProject.microServiceCommon.feignService"}) //Scan injection fallbackfactory

@EnableEurekaClient //Enable discovery services client

@EnableFeignClients(basePackages= {"com.lero.springCloud.shoppingProject.microServiceCommon.feignService"})  //Enable declarative service invocation client

It is configured in feign server in a completely decoupled way, providing fallbackfactory implementation class rewrite callback method, and also configured the fusing service using feign in the configuration file. The comedy is that the client calls the controller to display 404 errors all the time, and the fusing related configuration can be removed. It's obvious that using the controller is not successful. Isn't it because the controller doesn't inject the container and shouldn't. as long as the main program is outside, the Spring boot will scan the bean s together and inject them automatically. In addition, the RestController annotation is added. Quirky····

After many experiments and Baidu, it finally succeeded.

There is a problem with various annotations of the main program. Because Feign's services are extracted and encapsulated in Maven sub module, although the package has been introduced when the client consumes the call, it needs to add package scanning and inject the instance due to cross project reference API.

Here's the good part: I introduced feign service package and the callback class needed for fusing, which caused the above problems. If you don't configure fusing, it's OK

The final solution is to add the package name of your own project on the annotation declaration of the main program!!

It is suspected that other package names have been added. You must add your own package name to scan your own controller.


@SpringBootApplication(exclude={DataSourceAutoConfiguration.class},scanBasePackages= {"com.lero.springCloud.shoppingProject.microServiceCommon.feignService","com.lero.springCloud.shoppingProject.feignServiceConsumer"}) //Plus a scan of your own package

@EnableEurekaClient //Enable discovery services client

@EnableFeignClients(basePackages= {"com.lero.springCloud.shoppingProject.microServiceCommon.feignService","com.lero.springCloud.shoppingProject.feignServiceConsumer"})  //Enable declarative service invocation client

The most pitiful one is:

Java IDE can use Eclipse, MyEclipse charges

I'm so poor. Why do you ask me for money

Well, today's summary is here. I hope you can continue to forge ahead on the road of learning Java~

Finally, I'd like to present flowers to my friends who are learning Java as I used to

To encourage the young people who are still learning;

By the way, some small assistance

All of the above are my own thoughts. You are welcome to share them. By the way, I'd like to ask for a wave of attention. Please follow me and click[ Java ]You can get it for free~

Topics: Programming Java Database Spring SQL