Deploy an application that does not depend on the tomcat container. Deploy the tomcat container

Source: Internet
Author: User

Deploy an application that does not depend on the tomcat container. Deploy the tomcat container

A task project contains some scheduled tasks. I am not relying on tomcat to deploy the newly-established high-end agreed program.

The plan cannot keep up with the changes, and the task development has not yet been launched. The buddy is about to leave. During the work handover, I would like to explain how to deploy the service online.

 

As a result, when I deploy it on a linux testing server, it will take some twists and turns. Previously, applications were deployed under tomcat. Said Gao Kai, the deployment method that does not rely on tomcat containers is no longer a new concept. During the long process, some colleagues suggested that I give up and use tomcat instead. I think it is necessary to stick to it and eventually stick to it.

 

1. first introduce the project

Engineering example. There is a emax-paycenter-task.sh file under assembly/bin, mainly through the nohup command to run LauncherMain. As mentioned above, the shell file will be placed in the root directory of the application during deployment and the program will be started by executing it.

The following command is in the emax-paycenter-task.sh file, and start uses the nohup command:

LauncherMain. java is a main method used to initialize the environment:

Import ch. qos. logback. classic. loggerContext; import ch. qos. logback. classic. joran. joranaggregator; import org. slf4j. ILoggerFactory; import org. slf4j. logger; import org. slf4j. loggerFactory; import org. springframework. core. io. classPathResource; import org. springframework. web. context. support. xmlWebApplicationContext; import java.net. URL; import java. util. concurrent. semaphore;/*** Description start Method * Date 2018/2/8 am */public class LauncherMain {private static Logger logger = LoggerFactory. getLogger (LauncherMain. class); public static void main (String [] args) throws Exception {logger.info ("init @ Prop"); Semaphore sp = new Semaphore (0 ); xmlWebApplicationContext xmlWeb = new XmlWebApplicationContext (); xmlWeb. setConfigLocation ("classpath *: * spring/spring-applicationContext.xml"); String logbackCfg = "logback. xml "; URL logURL = new ClassPathResource (logbackCfg ). getURL (); ILoggerFactory loggerFactory = LoggerFactory. getILoggerFactory (); LoggerContext loggerContext = (LoggerContext) loggerFactory; JoranConfigurator aggregator = new JoranConfigurator (); aggregator. setContext (loggerContext); aggregator. doConfigure (logURL); xmlWeb. refresh (); xmlWeb. start (); sp. acquire ();}}

The Scheduled tasks involved in the project are implemented using Spring @ Scheduled:

@Componentpublic class AgentPayTask {    @Autowired    private LimitConfigDataHolder limitConfigDataHolder;    @Autowired    private AgentPayTaskService agentPayTaskService;    private static Logger logger = LoggerFactory.getLogger(AgentPayTask.class);    @Scheduled(cron ="0/5 * * * * ?")    public void process() {        System.out.println("AgentPayTask111");        logger.info("AgentPayTask");        Map<String, RateLimiterConfig> LimiterMap = limitConfigDataHolder.getAgentPayLimiter();        agentPayTaskService.distributeTask(LimiterMap);    }}

 

 

Ii. linux deployment

I am running the main method locally. The program is okay, and all the scheduled tasks in it can run normally.

Deploy the emax-paycenter-task-1.0.0-snapshot-assembly.tar.gz package on the test server. Final Command Execution

./emax-paycenter-task.sh start &

 

View the generated nohup. out file and find that class com. emax. paycenter. LauncherMain is always found.

After consulting and O & M, I found that the directory was not assigned permissions.

Skilled O & M also helped to correct the commands in the emax-paycenter-task.sh. The final result is as follows:

Run the preceding command again to start the program. Check the log file and find that there is only one log:

2018-03-21 15:11:45.381 [main] INFO  [com.emax.paycenter.LauncherMain] - init @Prop

 

Multiple tests showed that the program was executed to the sp. acquire (); this statement does not move; I did not print the log results after this statement; nor did the scheduled task run.

After learning about Semaphore semaphores, changing permits to 0 or 1 or other values won't work.

..... One hour ....

..... Two hours ....

It is fruitless to seek help from colleagues.

..... Several hours ....

Why is inspiration! I put the suspect focus to the setting of spring context. Isn't the setting successful at all?

xmlWeb.setConfigLocation("classpath*:*spring/spring-applicationContext.xml");

 

Is there a configuration file with the same name in each jar package? After changing the path parameter "classpath *: * spring/spring-applicationContext.xml" to "classpath: spring/spring-applicationContext.xml", check nohup. out to find a new problem:

[root@localhost emax-paycenter-task]# tail -f nohup.out at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:531)at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:295)... 11 moreCaused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.emax.paycenter.api.service.IPayCenterFacade] 
found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.
Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:997)at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:867)at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:779)at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:503)... 13 more

At the same time, a similar problem exists in the log file: An exception occurred during spring context initialization. The "AgentPayTaskQueryServiceImpl" class in the project injects Another bean "IPayCenterFacade" through @ Autowired dependency ".

However, the dependency "IPayCenterFacade" (NoSuchBeanDefinitionException) cannot be found in spring context, which causes spring context to fail to create the AgentPayTaskQueryServiceImpl instance "agentPayTaskQueryServiceImpl" (BeanCreationException ).

[Root @ localhost emax-paycenter-task] # tail-n200-f logback-task/task_info.log 16:16:37. 174 [main] INFO [com. emax. paycenter. launcherMain]-init @ Prop2018-03-21 16:16:39. 397 [main] WARN [org. springframework. web. context. support. xmlWebApplicationContext]-Exception encountered during context initialization-canceling refresh attemptorg. springframework. beans. factory. beanCreationException: Error creating bean with name 'agentpaytaskqueryserviceimpl': Injection of autowired dependencies failed; nested exception is org. springframework. beans. factory. beanCreationException: cocould not autowire field: private com. emax. paycenter. api. service. IPayCenterFacade com. emax. paycenter. service. impl. agentPayTaskQueryServiceImpl. payCenterFacade; nested exception is org. springframework. beans. factory. N OSuchBeanDefinitionException: No qualifying bean of type [com. emax. paycenter. api. service. IPayCenterFacade] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. dependency annotations: {@ org. springframework. beans. factory. annotation. autowired (required = true)} at org. springframework. beans. factory. annotation. autowiredAnnotationBeanPostProcessor. postPr OcessPropertyValues (AutowiredAnnotationBeanPostProcessor. java: 298 )~ [Spring-beans-3.2.13.RELEASE.jar: 3.2.13.RELEASE] at org. springframework. beans. factory. support. AbstractAutowireCapableBeanFactory. populateBean (AbstractAutowireCapableBeanFactory. java: 1148 )~ [Spring-beans-3.2.13.RELEASE.jar: 3.2.13.RELEASE] at org. springframework. beans. factory. support. AbstractAutowireCapableBeanFactory. doCreateBean (AbstractAutowireCapableBeanFactory. java: 519 )~ [Spring-beans-3.2.13.RELEASE.jar: 3.2.13.RELEASE] at org. springframework. beans. factory. support. AbstractAutowireCapableBeanFactory. createBean (AbstractAutowireCapableBeanFactory. java: 458 )~ [Spring-beans-3.2.13.RELEASE.jar: 3.2.13.RELEASE] at org. springframework. beans. factory. support. AbstractBeanFactory $1. getObject (AbstractBeanFactory. java: 293 )~ [Spring-beans-3.2.13.RELEASE.jar: 3.2.13.RELEASE] at org. springframework. beans. factory. support. DefaultSingletonBeanRegistry. getSingleton (DefaultSingletonBeanRegistry. java: 223 )~ [Spring-beans-3.2.13.RELEASE.jar: 3.2.13.RELEASE] at org. springframework. beans. factory. support. AbstractBeanFactory. doGetBean (AbstractBeanFactory. java: 290 )~ [Spring-beans-3.2.13.RELEASE.jar: 3.2.13.RELEASE] at org. springframework. beans. factory. support. AbstractBeanFactory. getBean (AbstractBeanFactory. java: 191 )~ [Spring-beans-3.2.13.RELEASE.jar: 3.2.13.RELEASE] at org. springframework. beans. factory. support. DefaultListableBeanFactory. preInstantiateSingletons (defalistlistablebeanfactory. java: 636 )~ [Spring-beans-3.2.13.RELEASE.jar: 3.2.13.RELEASE] at org. springframework. context. support. AbstractApplicationContext. finishBeanFactoryInitialization (AbstractApplicationContext. java: 934 )~ [Spring-context-3.2.13.RELEASE.jar: 3.2.13.RELEASE] at org. springframework. context. support. AbstractApplicationContext. refresh (AbstractApplicationContext. java: 479 )~ [Spring-context-3.2.13.RELEASE.jar: 3.2.13.RELEASE] at com. emax. paycenter. launcherMain. main (LauncherMain. java: 38) [emax-paycenter-task-1.0.0-SNAPSHOT.jar: na] Caused by: org. springframework. beans. factory. beanCreationException: cocould not autowire field: private com. emax. paycenter. api. service. IPayCenterFacade com. emax. paycenter. service. impl. agentPayTaskQueryServiceImpl. payCenterFacade; nested exception I S org. springframework. beans. factory. noSuchBeanDefinitionException: No qualifying bean of type [com. emax. paycenter. api. service. IPayCenterFacade] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. dependency annotations: {@ org. springframework. beans. factory. annotation. autowired (required = true)} at org. springframework. beans. factory. annotation. autowi RedAnnotationBeanPostProcessor $ AutowiredFieldElement. inject (AutowiredAnnotationBeanPostProcessor. java: 531 )~ [Spring-beans-3.2.13.RELEASE.jar: 3.2.13.RELEASE] at org. springframework. beans. factory. annotation. InjectionMetadata. inject (InjectionMetadata. java: 88 )~ [Spring-beans-3.2.13.RELEASE.jar: 3.2.13.RELEASE] at org. springframework. beans. factory. annotation. AutowiredAnnotationBeanPostProcessor. postProcessPropertyValues (AutowiredAnnotationBeanPostProcessor. java: 295 )~ [Spring-beans-3.2.13.RELEASE.jar: 3.2.13.RELEASE]... 11 common frames omittedCaused by: org. springframework. beans. factory. noSuchBeanDefinitionException: No qualifying bean of type [com. emax. paycenter. api. service. IPayCenterFacade] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. dependency annotations: {@ org. springframework. beans. factory. annota Tion. Autowired (required = true)} at org. springframework. beans. factory. support. DefaultListableBeanFactory. raiseNoSuchBeanDefinitionException (defalistlistablebeanfactory. java: 997 )~ [Spring-beans-3.2.13.RELEASE.jar: 3.2.13.RELEASE] at org. springframework. beans. factory. support. DefaultListableBeanFactory. doResolveDependency (defalistlistablebeanfactory. java: 867 )~ [Spring-beans-3.2.13.RELEASE.jar: 3.2.13.RELEASE] at org. springframework. beans. factory. support. DefaultListableBeanFactory. resolveDependency (defalistlistablebeanfactory. java: 779 )~ [Spring-beans-3.2.13.RELEASE.jar: 3.2.13.RELEASE] at org. springframework. beans. factory. annotation. AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement. inject (AutowiredAnnotationBeanPostProcessor. java: 503 )~ [Spring-beans-3.2.13.RELEASE.jar: 3.2.13.RELEASE]... 13 common frames omittedView Code

 

Finally, import the dubbo configuration file from spring applicationContext

<import resource="classpath*:*spring/dubbo-applicationContext.xml"/>

Change

<import resource="classpath:spring/dubbo-applicationContext.xml"/>

You can.

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.