Sunday, 15 January 2012

java - Do annotations on a class still get called when only accessing static members? -



java - Do annotations on a class still get called when only accessing static members? -

i have next class:

package hello; import org.springframework.boot.autoconfigure.enableautoconfiguration; import org.springframework.boot.springapplication; import org.springframework.context.annotation.componentscan; import org.springframework.stereotype.component; @component @enableautoconfiguration public class application { public static void main(string[] args) { springapplication.run(application.class, args); } }

if reference in main camel route, so:

package com.example.integration; import hello.*; import org.apache.camel.producertemplate; import org.springframework.context.applicationcontext; import org.springframework.context.support.classpathxmlapplicationcontext; public class testcamelspring { public static void main(string[] args) { applicationcontext context = new classpathxmlapplicationcontext("camelspring.xml"); producertemplate cameltemplate = context.getbean("cameltemplate", producertemplate.class); application.main(args); system.out.println("message sending started"); cameltemplate.sendbody("jms:queue:testqsource","sample message"); system.out.println("message sent"); } }

do annotations in application.class still accessed though reference application.main?

i inquire because @enableautoconfiguration supposed configure application tomcat, not running application.class directly, application defaulting jetty , error websockets supported in tomcat.

has had issue before or know how solve it?

here stack trace. can see console log never starts tomcat instance when whole class accessed in example. seems continuing if jetty app rather tomcat. please right me if of these assumptions wrong:

caused by: java.lang.illegalstateexception: websockets supported in tomcat (found class org.springframework.boot.context.embedded.jetty.jettyembeddedservletcontainerfactory). @ org.springframework.boot.autoconfigure.websocket.websocketautoconfiguration$1.customize(websocketautoconfiguration.java:74) @ org.springframework.boot.context.embedded.embeddedservletcontainercustomizerbeanpostprocessor.postprocessbeforeinitialization(embeddedservletcontainercustomizerbeanpostprocessor.java:67) @ org.springframework.boot.context.embedded.embeddedservletcontainercustomizerbeanpostprocessor.postprocessbeforeinitialization(embeddedservletcontainercustomizerbeanpostprocessor.java:54) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.applybeanpostprocessorsbeforeinitialization(abstractautowirecapablebeanfactory.java:407) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1545) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:539) ... 16 more

first of all, annotations cannot "called".

annotations data, not code. in case spring boot reads annotations when phone call springapplication.run(application.class, args); , performs necessary configurations, hence doesn't matter how phone call application.main().

i guess problem caused fact have jetty in classpath, , forces spring boot utilize jetty rather tomcat embedded servlet container.

so, seek following:

find out how jetty appeared in classpath utilize mvn dependency:tree -dverbose if utilize maven

if don't need jetty in classpath, exclude dependencies

otherwise, need forcefulness spring boot ignore presence of jetty exclude = embeddedservletcontainerautoconfiguration.embeddedjetty.class in @enableautoconfiguration may help

java spring tomcat

No comments:

Post a Comment