java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -
i getting error when run spring application:
exception in thread "main" org.springframework.context.applicationcontextexception: unable start embedded container; nested exception org.springframework.context.applicationcontextexception: unable start embeddedwebapplicationcontext due missing embeddedservletcontainerfactory bean. @ org.springframework.boot.context.embedded.embeddedwebapplicationcontext.onrefresh(embeddedwebapplicationcontext.java:124) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:476) @ org.springframework.boot.context.embedded.embeddedwebapplicationcontext.refresh(embeddedwebapplicationcontext.java:109) @ org.springframework.boot.springapplication.refresh(springapplication.java:691) @ org.springframework.boot.springapplication.run(springapplication.java:320) @ org.springframework.boot.springapplication.run(springapplication.java:952) @ org.springframework.boot.springapplication.run(springapplication.java:941) @ com.dh.test.application.main(application.java:13) caused by: org.springframework.context.applicationcontextexception: unable start embeddedwebapplicationcontext due missing embeddedservletcontainerfactory bean. @ org.springframework.boot.context.embedded.embeddedwebapplicationcontext.getembeddedservletcontainerfactory(embeddedwebapplicationcontext.java:174) @ org.springframework.boot.context.embedded.embeddedwebapplicationcontext.createembeddedservletcontainer(embeddedwebapplicationcontext.java:147) @ org.springframework.boot.context.embedded.embeddedwebapplicationcontext.onrefresh(embeddedwebapplicationcontext.java:121) ... 7 more
my main class looks like:
@configuration @componentscan public class application{ public static void main(string[] args) { springapplication.run(application.class, args); } }
i trying configure properties of spring through java classes using @bean:
@configuration @enablejparepositories( entitymanagerfactoryref = "customerentitymanager", transactionmanagerref = "customertransactionmanager", basepackages = {"com.dh.test.repository.customer"}) public class customerdbconfig { @bean public localcontainerentitymanagerfactorybean entitymanagerfactory(){ jpavendoradapter vendoradapter = new hibernatejpavendoradapter(); localcontainerentitymanagerfactorybean em = new localcontainerentitymanagerfactorybean(); em.setdatasource(datasource()); em.setpackagestoscan(new string[] {"com.dh.test.model.customer"}); em.setjpavendoradapter(vendoradapter); em.setjpaproperties(additionaljpaproperties()); em.setpersistenceunitname("customers"); return em; } properties additionaljpaproperties(){ properties properties = new properties(); properties.setproperty("hibernate.ddl-auto", "update"); properties.setproperty("jdbc.dialect", "org.hibernate.dialect.mysqldialect"); properties.setproperty("hibernate.show-sql", "true"); return properties; } @bean public datasource datasource(){ return datasourcebuilder.create() .url("jdbc:mysql://localhost:3306/customer") .driverclassname("com.mysql.jdbc.driver") .username("root") .password("root") .build(); } @bean public jpatransactionmanager transactionmanager(entitymanagerfactory customerentitymanager){ jpatransactionmanager transactionmanager = new jpatransactionmanager(); transactionmanager.setentitymanagerfactory(customerentitymanager); return transactionmanager; } }
extract of pom.xml
<?xml version="1.0" encoding="utf-8"?> <project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <groupid>org.test</groupid> <artifactid>boot-multidb-sample</artifactid> <version>0.0.1-snapshot</version> <packaging>jar</packaging> <name>boot-multidb-sample</name> <description>spring boot multiple database configuration</description> <parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>1.1.6.release</version> <relativepath /> <!-- lookup parent repository --> </parent> <dependencies> <!-- datasource , connection pool dependencies --> <!-- <dependency> <groupid>com.h2database</groupid> <artifactid>h2</artifactid> </dependency> --> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>5.1.33</version> </dependency> <dependency> <groupid>org.springframework.data</groupid> <artifactid>spring-data-jpa</artifactid> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-jpa</artifactid> <version>2.0.8</version> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot</artifactid> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-jdbc</artifactid> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-data-jpa</artifactid> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-webmvc</artifactid> </dependency> </dependencies> <build> <plugins> <plugin> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid> </plugin> </plugins> </build> </project>
can please give possible solution fix error, tried checking dependency hirerachy , dependencies in project.
it seems me embeddedservletcontainerfactory bean not initialized. need kick off:
add @springbootapplication annotation application class
@springbootapplication public class application { public static void main(string[] args) { springapplication.run(scheduledtasks.class, args); } }
the @springbootapplication annotation contains
- @configuration
- @componentscan
- @enableautoconfiguration (this 1 might fix problem)
also might need add spring-boot-starter-web dependency in pom:
<dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> </dependency>
Comments
Post a Comment