This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Bean | |
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { | |
http | |
.authorizeHttpRequests((authz) -> authz | |
.requestMatchers("/login", "/register") | |
.permitAll() // Login and register endpoints are accessible to allf | |
.anyRequest() | |
.authenticated() // Any other requests require authentication | |
) | |
.httpBasic(withDefaults()); // Enables basic authentication with default settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
@RequestMapping("/coffees") | |
public class CoffeeController { | |
@GetMapping("/{criteria}/details/{details}/reviews") | |
public String getCoffeeDetailsAndReviews(@MatrixVariable(pathVar = "criteria") Map<String, String> criteriaMatrixVars, | |
@MatrixVariable(pathVar = "details") Map<String, String> detailsMatrixVars) { | |
String roast = criteriaMatrixVars.get("roast"); | |
String origin = criteriaMatrixVars.get("origin"); | |
String flavor = criteriaMatrixVars.get("flavor"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
public class MyService { | |
public void methodA() { | |
// This method calls methodB internally | |
this.methodB(); | |
} | |
@Cacheable("myCache") | |
public String methodB() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
public class MessageProcessingService { | |
private final MessageProcessor<TextMessage> textMessageProcessor; | |
private final MessageProcessor<ImageMessage> imageMessageProcessor; | |
@Autowired | |
public MessageProcessingService(MessageProcessor<TextMessage> textMessageProcessor, | |
MessageProcessor<ImageMessage> imageMessageProcessor) { | |
this.textMessageProcessor = textMessageProcessor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface MessageProcessor<T> { | |
void process(T message); | |
} | |
@Component | |
public class TextMessageProcessor implements MessageProcessor<TextMessage> { | |
@Override | |
public void process(TextMessage message) { | |
// Processing logic for text messages | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
public class NotificationManager { | |
@Autowired | |
private List<NotificationService> notificationServices; | |
public void sendNotifications(String message, String recipient) { | |
for (NotificationService service : notificationServices) { | |
service.sendNotification(message, recipient); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface NotificationService { | |
void sendNotification(String message, String recipient); | |
String getServiceName(); | |
} | |
@Component | |
public class EmailNotificationService implements NotificationService { | |
public void sendNotification(String message, String recipient) { /* Email sending logic */ } | |
public String getServiceName() { return "Email"; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public abstract class SingletonService { | |
public void usePrototype() { | |
PrototypeService prototypeService = createPrototypeService(); | |
prototypeService.doSomething(); | |
} | |
@Lookup | |
public PrototypeService createPrototypeService() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public abstract class SingletonService { | |
public void usePrototype() { | |
PrototypeService prototypeService = createPrototypeService(); | |
prototypeService.doSomething(); | |
} | |
@Lookup | |
protected abstract PrototypeService createPrototypeService(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const CheckoutFormComponent = (props) => { | |
const stripe = useStripe(); | |
const elements = useElements(); | |
const { fullName, email } = props; | |
const [cardType, setCardType] = useState(""); | |
useEffect(() => {}, []); | |
const handleSubmit = async (event) => { | |
// Block native form submission. |
NewerOlder