dev
dev

Reputation: 11

WELD-001408: Unsatisfied dependencies for type DataSource with qualifiers @Named at injection point [BackedAnnotatedParameter]

I had a bean jdbc dataSource defined in applicationContext.xml. Here is my class TestDAO

    @Named
    public class TestDAO extends JdbcDaoSupport implements ITestDAO {
    @Inject
    TestDAO (@Named("dataSource") DataSource dataSource) {
        setDataSource(dataSource);
    }
    @Override
    public Map<String, Option> getLabelMap() {
        // Somce code invoke getJdbcTemplate().query        
            return map;
    }
    }   
Here is my Junit5 test which worked.
    @SpringJUnitConfig(locations = "file:src/main/webapp/WEB-INF/applicationContext.xml")
    class SimpleTest {
    @Autowired
    TestDAO tdao;   
    @Test
    void test() {
        Map<String, Option> mp = tdao.getLabelMap();
        assertEquals(2, mp.size());
    }
    }

I have applicationContext.xml, beans.xml, faces-config.xml, web.xml in WEB-INF.
Spring-core, context and web 6.0, WELD 5.1 in pom.xml
        <dependency>
            <groupId>org.jboss.weld.servlet</groupId>
            <artifactId>weld-servlet-shaded</artifactId>
            <version>5.1.0.Final</version>
        </dependency>

However, the war file failed to deploy in Tomcat 10.1.7, jdk 17 with an error of the injection of dataSource

INFO [Catalina-utility-2] org.jboss.weld.bootstrap.WeldStartup.<clinit> WELD-000900: 5.1.0 (Final)
INFO [Catalina-utility-2] org.jboss.weld.bootstrap.WeldStartup.startContainer WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
INFO [Catalina-utility-2] org.jboss.weld.environment.tomcat.TomcatContainer.initialize WELD-ENV-001100: Tomcat 7+ detected, CDI injection will be available in Servlets, Filters and Listeners.
SEVERE [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive 
SEVERE [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive 
    java.lang.IllegalStateException: Error starting child
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:686)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:658)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:713)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:975)
.....
    Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/pf4]]
        at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:683)
        ... 24 more
    Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type DataSource with qualifiers @Named
  at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject com.test.TestDAO(@Named DataSource)
  at com.test.TestDAO.<init>(TestDAO.java:0)

I tried to debug and search the error and CDI injection, but I haven't found a fix to make a war file deployed. My Junit5 test for this jdbc dataSource injection worked. Thanks,

Upvotes: 0

Views: 149

Answers (0)

Related Questions