Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b3bce4a

Browse files
Running code at startup
1 parent 3a85732 commit b3bce4a

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package com.naturalprogrammer.spring5tutorial.services;
22

3+
import org.springframework.boot.context.event.ApplicationReadyEvent;
4+
35
import com.naturalprogrammer.spring5tutorial.commands.UserCommand;
46

57
public interface UserService {
68

79
void signup(UserCommand userCommand);
10+
void afterApplicationReady(ApplicationReadyEvent event);
811
}

‎src/main/java/com/naturalprogrammer/spring5tutorial/services/UserServiceImpl.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package com.naturalprogrammer.spring5tutorial.services;
22

3+
import javax.annotation.PostConstruct;
4+
5+
import org.apache.commons.logging.Log;
6+
import org.apache.commons.logging.LogFactory;
7+
import org.springframework.boot.context.event.ApplicationReadyEvent;
8+
import org.springframework.context.event.EventListener;
39
import org.springframework.stereotype.Service;
410
import org.springframework.transaction.annotation.Propagation;
511
import org.springframework.transaction.annotation.Transactional;
@@ -13,12 +19,27 @@
1319
@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
1420
public class UserServiceImpl implements UserService {
1521

22+
private static Log log = LogFactory.getLog(UserServiceImpl.class);
23+
1624
private UserRepository userRepository;
1725

1826
public UserServiceImpl(UserRepository userRepository) {
1927

2028
this.userRepository = userRepository;
2129
}
30+
31+
@PostConstruct
32+
public void init() {
33+
34+
log.info("Inside Post construct");
35+
}
36+
37+
@Override
38+
@EventListener
39+
public void afterApplicationReady(ApplicationReadyEvent event) {
40+
41+
log.info("Inside afterApplicationReady");
42+
}
2243

2344
@Override
2445
@Transactional(propagation=Propagation.REQUIRED, readOnly=false)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.naturalprogrammer.spring5tutorial.utils;
2+
3+
import org.apache.commons.logging.Log;
4+
import org.apache.commons.logging.LogFactory;
5+
import org.springframework.boot.CommandLineRunner;
6+
import org.springframework.stereotype.Component;
7+
8+
@Component
9+
public class InitApp implements CommandLineRunner {
10+
11+
private static Log log = LogFactory.getLog(InitApp.class);
12+
13+
@Override
14+
public void run(String... arg0) throws Exception {
15+
log.info("Inside InitApp");
16+
}
17+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /