Created
June 28, 2016 12:15
-
-
Save hseritt/7f9d28cc279bf56fef66cfe49502afb2 to your computer and use it in GitHub Desktop.
Calling a bean that uses JPA Repository
This file contains hidden or 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
import java.io.IOException; | |
import java.sql.SQLException; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import org.springframework.context.ConfigurableApplicationContext; | |
@SpringBootApplication | |
public class AlfmonitorApplication { | |
public static void main(String[] args) throws ClassNotFoundException, SQLException, IOException, InterruptedException { | |
ConfigurableApplicationContext app = SpringApplication.run(AlfmonitorApplication.class, args); | |
Controller agentController = (Controller) app.getBean("controller"); | |
agentController.run(); | |
} | |
} |
This file contains hidden or 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
import java.util.List; | |
import org.apache.log4j.Logger; | |
import org.springframework.beans.factory.InitializingBean; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.stereotype.Component; | |
@Component | |
public class Controller implements Runnable, InitializingBean { | |
private static Logger logger = Logger.getLogger(Controller.class); | |
@Autowired | |
private AgentRepository agentRepository; | |
public void run() { | |
logger.info("Starting subsystem AgentController"); | |
List<Agent> activeAgents = agentRepository.findByActive(true); | |
for (Agent agent : activeAgents) { | |
logger.info(agent.getName()); | |
} | |
logger.info("Agent controller finished."); | |
} | |
@Override | |
public void afterPropertiesSet() throws Exception { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment