You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jun Suzuki <ju...@gmail.com> on 2024/02/05 14:53:10 UTC

How to deal with beans.xml during process of GraalVM native image build?

Within a spring framework application, it uses beanx.xml to define a
bean names "GreetingService":
<bean id="greetingService" class="com.example.service.GreetingService">
    <constructor-arg value="Hello from xml-based-config GreetingService" />
</bean>

 And this bean is being called as below:
===================================================================
 ApplicationContext context = new
ClassPathXmlApplicationContext("config/beans.xml");
        GreetingService greetingService =
(GreetingService)context.getBean("greetingService");
PrintWriter out = resp.getWriter();
out.println(greetingService.getGreetingMessage());
===================================================================

Above code runs perfectly as a war file on Tomcat. But when I try to
transform the war file into native image by following the
guidelines(https://tomcat.apache.org/tomcat-11.0-doc/graal.html),
maven build gave following errors:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile
(default-compile) on project tomcat-stuffed: Compilation failure
[ERROR] /home/opc/project/test/tomcat-native/stuffed/src/main/java/com/example/servlet/GreetServlet.java:[55,36]
cannot find symbol
[ERROR]   symbol:   method getGreetingMessage()
[ERROR]   location: variable greetingService of type
com.example.service.GreetingService

Beans.xml is under the "src/main/resources" folder. To which directory
should I copy the beans.xml under the stuffed folder?  ("conf" folder
or "src" folder?)
By the way, when using Java configuration to configure the bean
instead of using beans.xml, everything goes perfectly without errors.
May I confirm, whether XML-based bean configuration within a spring
framework application is also applicable to the process of AOT/GraalVM
support?

Jun

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org