Why is CamelExchangesFailed_total metrics not increased? - apache-camel

I have a Apache Camel application which is monitored by Prometheus. Therefore, I added Micrometer to my POM (see Spring Boot Auto-Configuration) and MicrometerRoutePolicyFactory to my application (see Using Micrometer Route Policy Factory). But the metric CamelExchangesFailed_total doesn't change, althought a route failed.
Source
#SpringBootApplication
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
#Bean
public MicrometerRoutePolicyFactory micrometerRoutePolicyFactory() {
return new MicrometerRoutePolicyFactory();
}
#Bean
public EndpointRouteBuilder route() {
return new EndpointRouteBuilder() {
#Override
public void configure() throws Exception {
errorHandler(deadLetterChannel("log:dead"));
from(timer("testTimer").repeatCount(1)).throwException(new RuntimeException());
}
};
}
}
Logs
INFO 5060 --- [ restartedMain] o.a.c.i.e.InternalRouteStartupManager : Route: route1 started and consuming from: timer://testTimer
INFO 5060 --- [ restartedMain] o.a.c.impl.engine.AbstractCamelContext : Total 1 routes, of which 1 are started
INFO 5060 --- [ restartedMain] o.a.c.impl.engine.AbstractCamelContext : Apache Camel 3.5.0 (camel-1) started in 0.007 seconds
INFO 5060 --- [ restartedMain] test.TestApplication : Started TestApplication in 6.626 seconds (JVM running for 7.503)
INFO 5060 --- [on(3)-127.0.0.1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
INFO 5060 --- [on(3)-127.0.0.1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
INFO 5060 --- [on(3)-127.0.0.1] o.s.web.servlet.DispatcherServlet : Completed initialization in 5 ms
INFO 5060 --- [mer://testTimer] dead : Exchange[ExchangePattern: InOnly, BodyType: null, Body: [Body is null]]
Metrics
# HELP CamelExchangesFailed_total
# TYPE CamelExchangesFailed_total counter
CamelExchangesFailed_total{application="test",camelContext="camel-1",routeId="route1",serviceName="MicrometerRoutePolicyService",} 0.0
# HELP CamelExchangesSucceeded_total
# TYPE CamelExchangesSucceeded_total counter
CamelExchangesSucceeded_total{application="test",camelContext="camel-1",routeId="route1",serviceName="MicrometerRoutePolicyService",} 1.0
Resaerch
If I remove the custom error handler, the metric CamelExchangesFailed_total is increased, but then the default error handler is used, which is not desired for some reasons.
Question
Why is CamelExchangesFailed_total metrics not increased? Is there any way to count all failed routes with a custom error handler?

Apache Camel LTS version 3.7.0 added a new metric CamelExchangesFailuresHandled_total, which is a counter of handled errors, see CAMEL-15908:
Similar to CAMEL-15255, there are some additional counter metrics we could add to the MicrometerRoutePolicy for:
Total exchanges processed
Number of failures handled
Number of external redeliveries
Metrics
# HELP CamelExchangesFailed_total
# TYPE CamelExchangesFailed_total counter
CamelExchangesFailed_total{application="test",camelContext="camel-1",routeId="route1",serviceName="MicrometerRoutePolicyService",} 0.0
# HELP CamelExchangesSucceeded_total
# TYPE CamelExchangesSucceeded_total counter
CamelExchangesSucceeded_total{application="test",camelContext="camel-1",routeId="route1",serviceName="MicrometerRoutePolicyService",} 1.0
# HELP CamelExchangesFailuresHandled_total
# TYPE CamelExchangesFailuresHandled_total counter
CamelExchangesFailuresHandled_total{application="test",camelContext="camel-1",routeId="route1",serviceName="MicrometerRoutePolicyService",} 1.0

Related

Jbang camel app not able to expose jetty component based route

When using the jbang cli jbang RestCamelJbang.java below code expose the REST endpoint successfully. Able to access the endpint at 8080
///usr/bin/env jbang "$0" "$0" : exit $?
// camel-k: language=java
//DEPS org.apache.camel:camel-bom:3.20.1#pom
//DEPS org.apache.camel:camel-core
//DEPS org.apache.camel:camel-main
//DEPS org.apache.camel:camel-jetty
//DEPS org.slf4j:slf4j-nop:2.0.6
//DEPS org.slf4j:slf4j-api:2.0.6
import org.apache.camel.*;
import org.apache.camel.builder.*;
import org.apache.camel.main.*;
import org.apache.camel.spi.*;
import static java.lang.System.*;
public class RestCamelJbang{
public static void main(String ... args) throws Exception{
out.println("Starting camel route...");
setProperty("org.slf4j.simpleLogger.logFile", "System.out");
Main main = new Main();
main.configure().addRoutesBuilder(new RouteBuilder(){
public void configure() throws Exception{
out.println("Camel configuration started...");
from("jetty:http://localhost:8080/hello")
.transform().simple("First Message of Camel");
}
});
main.run();
}
}
When using the Jbang Camel app camel run FirstCamel.java command with the jetty component, there are NO exception in the console but states 0 route started.
The endpoint http://localhost:8080/hello there is no response.
Am I missing something here, do we need some sort of server to run it?
///usr/bin/env jbang "$0" "$0" : exit $?
// camel-k: language=java
import org.apache.camel.*;
import org.apache.camel.builder.*;
import org.apache.camel.main.*;
import org.apache.camel.spi.*;
public class FirstCamel extends RouteBuilder{
#Override
public void configure() throws Exception{
from("jetty:http://localhost:8081/hello")
.transform().simple("First Message of Camel")
.log("${body}");
}
}
Console ouput
2023-02-13 21:10:22.056 INFO 6884 --- [ main] org.apache.camel.main.MainSupport : Apache Camel (JBang) 3.20.1 is starting
2023-02-13 21:10:22.511 INFO 6884 --- [ main] org.apache.camel.main.MainSupport : Using Java 17.0.1 with PID 6884. Started by thirumurthi in C:\thiru\learn\camel\camel_lessons\lesson
2023-02-13 21:10:22.543 INFO 6884 --- [ main] he.camel.cli.connector.LocalCliConnector : Camel CLI enabled (local)
2023-02-13 21:10:24.180 INFO 6884 --- [ main] .main.download.MavenDependencyDownloader : Downloaded: org.apache.camel:camel-rest:3.20.1 (took: 1s55ms)
2023-02-13 21:10:24.471 INFO 6884 --- [ main] e.camel.impl.engine.AbstractCamelContext : Apache Camel 3.20.1 (CamelJBang) is starting
2023-02-13 21:10:24.893 INFO 6884 --- [ main] e.camel.impl.engine.AbstractCamelContext : Routes startup (started:0)
2023-02-13 21:10:24.893 INFO 6884 --- [ main] e.camel.impl.engine.AbstractCamelContext : Apache Camel 3.20.1 (CamelJBang) started in 950ms (build:289ms init:241ms start:420ms JVM-uptime:5s)
Below code works when I use the rest DSL with camel run WelcomeRoute.java.
import org.apache.camel.*;
import org.apache.camel.builder.RouteBuilder;
public class WelcomeRoute extends RouteBuilder {
#Override
public void configure() throws Exception {
restConfiguration().bindingMode("auto");
rest("/api")
.get("/demo/{info}")
.to("log:info")
.to("direct:msg");
from("direct:msg")
.transform().simple("msg received - ${header.info}");
}
}
When using Camel JBang run then its for running Camel routes (not Java Main classes). So the first code is not valid.
Camel JBang detects Java source that are RouteBuilder so your class should extend this class, like the 2nd and 3rd code examples.
There has been some troubles with Java 11 and older Camel releases to use .java source with java imports. That works with Java 17, so upgrade if you can. Otherwise you may need to use FQN classnames instead of imports.

QuarkusIntegrationTest does not allow two tests running sequentially: application closed in 2nd test by Camel SimpleMainShutdownStrategy

I have a strange error: I can only run one Quarkus integration test in my mvn verify step. When I have two integration tests, the second one runs but immediately stops the application so nothing is happening and building hangs forever.
The logs are different in two tests. For the 1st one, the logs are:
2023-01-04 15:43:04,560 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Routes startup (total:8 started:8)
2023-01-04 15:43:04,560 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Started route1 (activemq://queue:myqueue)
2023-01-04 15:43:04,560 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Started route2 (activemq://queue:myqueue.online)
2023-01-04 15:43:04,560 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Started main (direct://main)
2023-01-04 15:43:04,560 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Started individual-endpoint (direct://individual-endpoint)
2023-01-04 15:43:04,560 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Started send-and-retry (direct://send-and-retry)
2023-01-04 15:43:04,560 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Started mapping-response (direct://mapping-response)
2023-01-04 15:43:04,560 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Started reply-queue (direct://reply-queue)
2023-01-04 15:43:04,560 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Started route3 (direct://receive.ack.response)
2023-01-04 15:43:04,561 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Apache Camel 3.14.1 (camel-1) started in 593ms (build:0ms init:206ms start:387ms)
2023-01-04 15:43:04,562 DEBUG [org.apa.cam.imp.DefaultCamelContext] (main) start() took 594 millis
2023-01-04 15:43:04,567 DEBUG [org.apa.cam.mai.SimpleMainShutdownStrategy] (camel-main) Await shutdown to complete
2023-01-04 15:43:04,583 INFO [com.example.MyLogger] (main) Application is up
2023-01-04 15:43:04,583 INFO [com.example.MyLogger] (main) Application is up
2023-01-04 15:43:04,767 INFO [com.example.ShutdownController] (main) Setting pre shutdown sleep time to 10 seconds.
2023-01-04 15:43:04,767 INFO [io.quarkus] (main) my-app 0.0.1-SNAPSHOT on JVM (powered by Quarkus 2.7.5.Final) started in 3.124s. Listening on: http://0.0.0.0:8081
2023-01-04 15:43:04,768 INFO [io.quarkus] (main) Profile integration activated.
...(application runs normally; sends a message to in memory AMQ broker and Camel starts consuming from the queue)
And the 2nd test runs with these logs:
2023-01-04 15:43:59,606 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Routes startup (total:8 started:8)
2023-01-04 15:43:59,606 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Started route1 (activemq://queue:myqueue)
2023-01-04 15:43:59,606 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Started route2 (activemq://queue:myqueue.online)
2023-01-04 15:43:59,606 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Started main (direct://main)
2023-01-04 15:43:59,606 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Started individual-endpoint (direct://individual-endpoint)
2023-01-04 15:43:59,606 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Started send-and-retry (direct://send-and-retry)
2023-01-04 15:43:59,606 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Started mapping-response (direct://mapping-response)
2023-01-04 15:43:59,606 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Started reply-queue (direct://reply-queue)
2023-01-04 15:43:59,606 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Started route3 (direct://receive.ack.response)
2023-01-04 15:43:59,606 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Apache Camel 3.14.1 (camel-1) started in 452ms (build:0ms init:202ms start:250ms)
2023-01-04 15:43:59,607 DEBUG [org.apa.cam.imp.DefaultCamelContext] (main) start() took 453 millis
2023-01-04 15:43:59,631 INFO [com.example.MyLogger] (main) Application is up
2023-01-04 15:43:59,631 INFO [com.example.MyLogger] (main) Application is up
2023-01-04 15:43:59,617 DEBUG [org.apa.cam.mai.SimpleMainShutdownStrategy] (camel-main) Await shutdown to complete
2023-01-04 15:43:59,756 INFO [com.example.MyLogger] (main) Application is down
2023-01-04 15:43:59,756 INFO [com.example.MyLogger] (main) Application is down
2023-01-04 15:43:59,757 DEBUG [org.apa.cam.mai.SimpleMainShutdownStrategy] (main) Shutdown called
2023-01-04 15:43:59,757 DEBUG [org.apa.cam.mai.MainLifecycleStrategy] (main) CamelContext: camel-1 is stopping, triggering shutdown of the JVM.
The class ShutdownController listens for Quarkus shutdown event.
public class ShutdownController implements ShutdownListener {
static final Logger LOGGER = LoggerFactory.getLogger(ShutdownController.class);
private final long preShutdownSleep;
public ShutdownController() {
this.preShutdownSleep = (Long)ConfigProvider.getConfig().getOptionalValue("com.example.shutdown-controller.pre-shutdown-sleep", Long.class).orElse(ProfileManager.getLaunchMode() == LaunchMode.TEST ? 0L : 10L);
LOGGER.info("Setting pre shutdown sleep time to {} seconds.", this.preShutdownSleep);
}
public ShutdownController(final int preShutdownSleep) {
this.preShutdownSleep = (long)preShutdownSleep;
}
public void preShutdown(final ShutdownNotification notification) {
LOGGER.info("Pre shutdown received. Waiting fully functionally for {} seconds.", this.preShutdownSleep);
this.sleep();
LOGGER.info("Continuing shutdown");
notification.done();
}
private void sleep() {
try {
TimeUnit.SECONDS.sleep(this.preShutdownSleep);
} catch (InterruptedException var2) {
Thread.currentThread().interrupt();
}
}
}
Notice that Camel SimpleMainShutdownStrategy is called but in the second test, it does not wait for 10s. Why?
I see this part in SimpleMainShutdownStrategy class:
#Override
public boolean isRunAllowed() {
return !completed.get();
}
#Override
public void addShutdownListener(ShutdownEventListener listener) {
listeners.add(listener);
}
#Override
public boolean shutdown() {
if (completed.compareAndSet(false, true)) {
LOG.debug("Shutdown called");
latch.countDown();
for (ShutdownEventListener l : listeners) {
try {
LOG.trace("ShutdownEventListener: {}", l);
l.onShutdown();
} catch (Throwable e) {
// ignore as we must continue
LOG.debug("Error during ShutdownEventListener: {}. This exception is ignored.", l, e);
}
}
return true;
}
return false;
}
#Override
public void await() throws InterruptedException {
LOG.debug("Await shutdown to complete");
latch.await();
}
So maybe it is because in the 1st case, ShutdownController has no instance so the constructor is called, and wait for 10s; but in the 2nd test, the instance is created so it does not call constructor. But why shutdown is called before the integration test runs?
In both cases, Quarkus app starts before Camel.
Both tests have similar structure:
#QuarkusIntegrationTest
#QuarkusTestResource(value = WiremockResource.class, restrictToAnnotatedClass = true)
#QuarkusTestResource(value = InMemoryAMQResource.class, restrictToAnnotatedClass = true)
#TestProfile(MyIntegrationTestProfile.class)
class MyOutboundMessageFormatIT extends MyIntegrationTestSupport { // the base class have a lot of fields like connetion, session, etc., which are used in #BeforeAll and #BeforeEach, etc.
private static final Logger LOG = Logger.getLogger(MyOutboundMessageFormatIT.class);
#InjectInMemoryAMQ
protected BrokerService brokerService;
#InjectWiremock
protected WireMockServer wireMockServer;
#Override
WireMockServer getWiremock() {
return wireMockServer;
}
#Override
BrokerService getBroker() {
return brokerService;
}
#BeforeAll
protected static void start() throws Exception {
LOG.debug("Connecting to AMQ");
connectToAMQ();
}
#AfterAll
protected static void stop() throws Exception {
LOG.debug("Stopping AMQ");
session.close();
connection.stop();
connection.close();
}
#BeforeEach
protected void stub() {
// global stubs
stubAllFieldsOK();
stubOauthOK();
}
#AfterEach
protected void clearWiremockRequestsJournal() throws JMSException {
// clear reply queue for next test
consumeOnlineReply();
assertEmptyNonOnlineReply();
waitTillTokenExpires();
wireMockServer.resetRequests();
}
...
At last, at the end of the log I see the cause:
2023-01-05 14:13:52,530 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Apache Camel 3.14.1 (camel-1) shutdown in 942ms (uptime:1s341ms)
2023-01-05 14:13:52,549 ERROR [io.qua.run.Application] (main) Port 8081 seems to be in use by another process. Quarkus may already be running or the port is used by another application.
2023-01-05 14:13:52,549 WARN [io.qua.run.Application] (main) Use 'netstat -anop | grep 8081' to identify the process occupying the port.
2023-01-05 14:13:52,549 WARN [io.qua.run.Application] (main) You can try to kill it with 'kill -9 <pid>'.
So actually there cannot be 2 integration tests running; seems Quarkus application can only start once and will occupy the port.
At last, I solved this by allowing duplicate message in my ActiveMQ in memory broker URL, and put all cases into one test.
The original issue is that I was reusing the JSON message body between tests, and somehow ActiveMQ is ignoring the message, so no message entered the queue, so 2nd test was not running; also, changing stubbing out of Wiremock resource class seems impossible(at first I let Wiremock return 200, but in the last test I want to simulate 404 case), that's why I wanted to separate the tests.
Now, I use an id to mark the stub I want to change, and in test I call wiremockServer.editStub() to change the stub, also I stop tests from running in parallel with #TestMethodOrder(value = MethodOrderer.MethodName.class), then things start to work. So no dividing into 2 test classes is needed now.

Apache camel pollEnrich strangeness

I am having a number of type conversion issues using the Java DSL with Camel 3.14.3. For a simple example I have a route that uses a direct endpoint to trigger a pollEnrich for a file endpoint.
public class BasicRoute extends RouteBuilder {
#Override
public void configure() {
from("direct:test")
.pollEnrich("file://watchDirectory", 10000)
.to("mock:result");
}
}
When the route starts I get the following exception...
Exception in thread "main" org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> PollEnrich[constant{file://watchDirectory}] <<< in route: Route(route1)[From[direct:test] -> [PollEnrich[constant{file... because of Error parsing [10000] as a java.time.Duration.
...
Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: java.lang.String to the required type: java.time.Duration with value 10000
I am running this within a simple OG java app, so I am sure I am missing something in the context initialization, but I cannot find it.

concurrentConsumers not created right away from beginning

I am using Camel in a Spring-Boot application to route from AMQ-Queue. Messages from this queue will be sent to a REST-Webservice. It is already working with this code line:
from("amq:queue:MyQueue").process("jmsToHttpProcessor").to(uri);
My uri looks like this:
http4://localhost:28010/application/createCustomer
Now I have the requirement that the routing to the Webservice should be done parallely:
In order to achive that, I configured concurrentConsumers in JmsConfiguration as follows:
#Bean
public JmsComponent amq(#Qualifier("amqConnectionFactory") ConnectionFactory amqConnectionFactory, AMQProperties amqProperties) {
JmsConfiguration jmsConfiguration = new JmsConfiguration(amqConnectionFactory);
jmsConfiguration.setConcurrentConsumers(50);
jmsConfiguration.setMaxConcurrentConsumers(50);
return new JmsComponent(jmsConfiguration);
}
#Bean
public ConnectionFactory amqConnectionFactory(AMQProperties amqProperties) throws Exception {
ConnectionFactoryParser parser = new ConnectionFactoryParser();
ConnectionFactory returnValue = parser.newObject(parser.expandURI(amqProperties.getUrl()), "amqConnectionFactory");
return returnValue;
}
It is working as expected, BUT not right away from the beginning. I have the phenomenon:
I have 100 messages in the ActiveMQ queue
I start my Spring application
Camel creates only 1 thread consuming 1 message after the previous one gets response
I observe that the amount of messages in queue only decreasing slowly(99.... 98... 97... 96...)
I am filling the queue with new 100 messages
NOW the concurrent consumers are being created as I can observe that the messages decreasing rapidly.
Does someone have any idea, why the concurrentConsumers is not working right away from the beginning?
I tried the advices. Unfortunately they dont change the behaviour. I found out, that the problem is that Camel already starts consuming the messages from the queue before the Spring boot application is startet. I can observe this from the log:
2021-04-01T20:26:33,901 INFO (Camel (CamelBridgeContext) thread #592 - JmsConsumer[MyQueue]) [message]; ...
2021-04-01T20:26:33,902 INFO (Camel (CamelBridgeContext) thread #592 - JmsConsumer[MyQueue]) [message]; ...
2021-04-01T20:26:33,915 INFO (main) [AbstractConnector]; _; Started ServerConnector#5833f5cd{HTTP/1.1,[http/1.1]}{0.0.0.0:23500}
2021-04-01T20:26:33,920 INFO (main) [BridgeWsApplication]; _; Started BridgeWsApplication in 12.53 seconds (JVM running for 13.429)
In this case, only one consumer with thread #592 is consuming all the messages.
In fact, if I start my Spring application first, and then fill the queue with messages, then concurrentConsumers will be used:
2021-04-01T20:30:20,159 INFO (Camel (CamelBridgeContext) thread #594 - JmsConsumer[MyQueue])
2021-04-01T20:30:20,159 INFO (Camel (CamelBridgeContext) thread #599 - JmsConsumer[MyQueue])
2021-04-01T20:30:20,178 INFO (Camel (CamelBridgeContext) thread #593 - JmsConsumer[MyQueue])
2021-04-01T20:30:20,204 INFO (Camel (CamelBridgeContext) thread #564 - JmsConsumer[MyQueue])
In this case, messages are being consumed from concurrentConsumers parallely.
In order to solve the problem, I tried setting autoStartUp to false in my RouteBuilder component:
#Override
public void configure() {
CamelContext context = getContext();
context.setAutoStartup(false);
// My Route
}
In my naive thinking, I let Camel starting after the Spring boot is started and running:
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(BridgeWsApplication.class, args);
SpringCamelContext camel = (SpringCamelContext) context.getBean("camelContext");
camel.start();
try {
camel.startAllRoutes();
} catch (Exception e) {
e.printStackTrace();
}
}
Unfortunately, this does not change the behaviour. There must be a configuration to let Camel starts after Spring is started.

how to extract data from ElementCollection

I am trying to extract data from an ElementCollection that is contained in StandartFont.
public class DBFonts {
#Id
#GeneratedValue(strategy= GenerationType.AUTO)
private long id;
private String nameFont;
#ElementCollection
#CollectionTable(
name="StandartFont",
joinColumns=#JoinColumn(name="Fonts_id")
#Lob #Basic(fetch = FetchType.LAZY)
#Column(length=100000)
private List<byte[]> StandartFonts; }
Repository:
public interface FontRepo extends JpaRepository<DBFonts,Long> {
List<byte[]> findByStandartFonts(Long fonsId);
}
HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
Hibernate: alter table font add constraint FKpcplr5ixrmh5lbjx0e6peoqo4 foreign key (user_id) references usr (id)
Hibernate: alter table standart_font add constraint FKq7nxy6see56tp2y997fwmsewq foreign key (fonts_id) references font (id)
2018-12-06 16:15:54.338 INFO 6168 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-12-06 16:15:54.884 WARN 6168 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'addFont': Unsatisfied dependency expressed through field 'fontRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fontRepo': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List spring_mvc.entity.FontRepo.findByStandartFonts(java.lang.Long)! Unable to locate Attribute with the the given name [standartFonts] on this ManagedType [spring_mvc.entity.DBFonts]
2018-12-06 16:15:54.884 INFO 6168 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2018-12-06 16:15:54.886 INFO 6168 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2018-12-06 16:15:54.896 INFO 6168 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2018-12-06 16:15:54.898 INFO 6168 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2018-12-06 16:15:54.916 INFO 6168 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-12-06 16:15:54.928 ERROR 6168 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'addFont': Unsatisfied dependency expressed through field 'fontRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fontRepo': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List spring_mvc.entity.FontRepo.findByStandartFonts(java.lang.Long)! Unable to locate Attribute with the the given name [standartFonts] on this ManagedType [spring_mvc.entity.DBFonts]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:586) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.0.5.RELEASE.jar:2.0.5.RELEASE]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fontRepo': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List spring_mvc.entity.FontRepo.findByStandartFonts(java.lang.Long)! Unable to locate Attribute with the the given name [standartFonts] on this ManagedType [spring_mvc.entity.DBFonts]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1699) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
It does not work, how to extract data correctly?
Will it work?:
select standart_fonts FROM standart_font where fonts_id=?
How to write this in #Query
Spring cant find attribute with name standartFonts in your class DBFonts and that's why it can't create been with your repository
Unable to locate Attribute with the the given name [standartFonts] on
this ManagedType [spring_mvc.entity.DBFonts]
Spring using reflection get method name (findByStandartFonts) from your repository and parse it: findBy its means select and StandartFonts spring parse as standartFonts and it try to find this field in your #Entity
PS. In id field, please, use Long instead of long. It's good practice.
And use camelCase in your java code...

Resources