weblogic 12c中未检测到.war(使用spring boot生成)中的主类

时间:2018-10-06 05:50:19

标签: java spring maven spring-boot weblogic12c

到目前为止,我已经可以将.war文件(使用Spring Boot构建)部署到weblogic 12c中。现在,我不确定我是否遇到问题或weblogic中的.war是否表现出预期的效果。

当.war文件部署到weblogic 12c服务器中时,我的春季启动项目中似乎没有运行一个主类(KafkaProducerSpringBootApplication)。在下面找到我的代码和配置:

--------------主类-----

    package com.springBoot.producer;

import java.util.Properties;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringSerializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.web.WebApplicationInitializer;

@SpringBootApplication
public class KafkaProducerSpringBootApplication extends SpringBootServletInitializer implements WebApplicationInitializer{

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(KafkaProducerSpringBootApplication.class);
    }

    private static final Logger logger = LoggerFactory.getLogger(KafkaProducerSpringBootApplication.class.getName());

    public static void main(String[] args) {
        SpringApplication.run(KafkaProducerSpringBootApplication.class, args);  

        logger.info("__KafkaProducerSpringBootApplication_Application_Started");   
        logger.debug("__KafkaProducerSpringBootApplication_Application_StartedDebug");

                String bootstrapServers = "1.1.1.11:9092";
                // Create the producer properties

                Properties prop = new Properties();

                prop.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,bootstrapServers);
                prop.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
                prop.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,StringSerializer.class.getName());

                // Create the producer
                KafkaProducer<String,String> producer = new KafkaProducer<String, String>(prop);

                // Create a producer record
                ProducerRecord<String,String> record = new ProducerRecord<String,String>("sample_topic_springBoot_uat","HelloPrapanchamfrom producer weblogic");

                logger.info("Key_debug_KafkaProducerSpringBootApplication:" +record.key() + ", Value_debug_KafkaProducerSpringBootApplication:" + record.value());

                // send data - Async
                producer.send(record);

                // flush data
                producer.flush();
                // flush and close producer
                producer.close();           
    }
}

------------------- 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>com.springBoot.producer</groupId>
    <artifactId>KafkaProducerSpringBoot</artifactId>
    <version>0.0.5-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>KafkaProducerSpringBoot</name>
    <description>Demo project for simple kafka producer using Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <start-class>com.springBoot.producer.KafkaProducerSpringBootApplication</start-class>
        <java.version>1.7</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.kafka/kafka -->
        <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka-clients</artifactId>
            <version>1.0.1</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

            <plugin>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-war-plugin</artifactId>
                 <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <archive>
                       <manifest>
                          <addDefaultImplementationEntries>false</addDefaultImplementationEntries>
                       </manifest>
                    </archive>
                 </configuration>
            </plugin>

        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>


</project>

------------------- weblogic.xml --------------

    <?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee         http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd         http://xmlns.oracle.com/weblogic/weblogic-web-app         http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">

    <!-- <wls:context-root>/KafkaProducerSpringBoot</wls:context-root> -->
    <wls:container-descriptor>
        <wls:prefer-application-packages>
            <wls:package-name>org.slf4j</wls:package-name>
            <wls:package-name>org.springframework.*</wls:package-name>
        </wls:prefer-application-packages>
    </wls:container-descriptor>
</wls:weblogic-web-app>

----------------- application.properties ----------

   logging.level.root=WARN
logging.level.com.springBoot.producer.KafkaProducerSpringBootApplication=INFO
logging.file=/opt/oracle/applications/ProducerDemoSpringboot/logs/springBootProducerDemo789.log
#logging.path=/opt/oracle/applications/ConsumerDemoSpringboot/logs/springBootConsumerDemo.log

将战争部署到weblogic12c之后,我可以看到以下日志:

  2018-10-06 00:44:17.347  INFO 21398 --- [ (self-tuning)'] c.s.p.KafkaProducerSpringBootApplication : No active profile set, falling back to default profiles: default

2018-10-06 00:44:18.982  INFO 21398 --- [ (self-tuning)'] c.s.p.KafkaProducerSpringBootApplication : Started KafkaProducerSpringBootApplication in 2.04 seconds (JVM running for 43256.89)

然后,我在日志中看不到任何内容。如果您观察我的主类,那么我正在打印一些记录器,以查看主类是否正在执行。但是我在主班上没有看到任何记录器。

观察: 如果我通过更改

来构建相同的代码

<packaging>war</packaging><packaging>jar</packaging>

并将 .jar 复制到 domain / lib 文件夹,并使用以下命令-

执行
java -jar KafkaProducerSpringBoot-0.0.5-SNAPSHOT.jar

然后我可以在weblogic服务器中看到我的记录器(在主类中定义)。不知道发生了什么。

有人可以在这里指出我要出问题的地方吗?为什么我的主类没有得到执行?

0 个答案:

没有答案