Home > Back-end >  Springboot section can't response
Springboot section can't response

Time:11-21

Defines a plane
 
Package com. Javastudy. Study;

The import org. Aspectj. Lang. The annotation. AfterReturning;
The import org. Aspectj. Lang. The annotation. AfterThrowing;
The import org. Aspectj. Lang. The annotation. Before;
The import org. Aspectj. Lang. The annotation. The Aspect;
The import org. Aspectj. Lang. The annotation. Pointcut;
The import org.springframework.stereotype.Com ponent;

@ Aspect
@ Component
Public class on {
The @pointcut (" execution (public * com. Javastudy. Study. IPerformance. Perform (.. )))
Public void performance () {}

@ Before (" performance () ")
Public void silenceCellPhone () {
System. The out. Println (" Silence cell phones ");
}

@ Before (" performance () ")
Public void takeSeats () {
System. The out. Println (" Take seats ");
}

@ AfterReturning (performance "()")
Public void applause () {
System. The out. Println (" CLAP CLAP CLAP ");
}

@ AfterThrowing (performance "()")
Public void demandRefund () {
System. The out. Println (" Demanding a refund ");
}
}


Defines the aspects of the target class
 
Package com. Javastudy. Study;

The import org.springframework.stereotype.Com ponent;

@ Component
Public class SingPerformance implements IPerformance {
Public void the perform () {
System. The out. Println (" I will sing a song. ");
}

Public static void main (String [] args) {
System. The out. Println (" the test perform. ");
SingPerformance p=new SingPerformance ();
P.p erform ();
}
}


Calls can be activated in the Controller plane, but the main function, direct call SingPerformance perform functions do not work
 
Ackage com. Javastudy. Study;

import org.springframework.beans.factory.annotation.Autowired;
The import org. Springframework. Web. Bind. The annotation. GetMapping;
The import org. Springframework. Web. Bind. The annotation. RequestMapping;
The import org. Springframework. Web. Bind. The annotation. RestController;

@ RestController
@ RequestMapping ("/perform ")
Public class performanceController {
The @autowired
SingPerformance perform;

@ GetMapping ("/1 ")
Public void perform1 () {
Perform. The perform ();
}

Public static void main (String [] args) {
SingPerformance performance=new SingPerformance ();;
Performance. The perform ();
}
}

CodePudding user response:

What do you mean run directly the main method aspect doesn't work?

CodePudding user response:

What new out of the object directly, you can come to the edge?

If you want to separate unit tests, you can use spring - junit test, or you haven't started the spring framework, there is no concept of ioc and aop,

You can know about the principle of aop is first? The principle of aop is injection is an additional proxy objects, rather than your native objects, so we can give you enter into the plane,

CodePudding user response:

The
reference 1/f, XLS, reply:
what do you mean run directly the main method aspect doesn't work?

Yes, open a browser to access the interface effect
  • Related