2017-09-19 3 views
0

私はclientDAOインターフェイスとclientDaoImplクラスを持っています。私はclientDAOでメソッドを宣言し、clientDaoImplでメソッドを定義しました。また、spring-servlet.xml(spring-configファイル)のmysqlデータベース接続をデータソースとして定義します。どのようにDAOメソッドを使用してデータベースにデータを挿入するのですか?

import java.util.Date; 
import org.springframework.stereotype.Controller; 

import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.RequestParam; 
import org.springframework.web.bind.annotation.ResponseBody; 
import org.springframework.web.bind.annotation.SessionAttributes; 
import org.springframework.web.servlet.ModelAndView; 
import org.springframework.web.bind.annotation.RequestMapping; 

@SessionAttributes 
@Controller 
public class clientRegistrationController { 
@Autowired 
private clientDAO clientdao; 
    @SessionAttributes 
    @Controller 
    public class ClientRegistrationController { 


    @RequestMapping(value="/registration",method = RequestMethod.POST) 
     public @ResponseBody 
     String client_registration(@RequestParam(value = "date_of_registration") Date date_of_registration) 

     // here i want to get pojo object and call method insert method which is 
     // defined in DAO implement class. 
       return " Registered successfully";  

     } 
@RequestMapping("/registration") 
    public ModelAndView showContacts() { 
    String message = "Hello World, Spring MVC @ Javatpoint"; 
     return new ModelAndView("client_registration", "message",message); 
    } 
} 

私は、次のエラーました:私はこれが私のclientdaoあるjavatpoint.com で利用可能/ SpringTilesコードを使用

SEVERE: Servlet [spring] in web application [/SpringTiles] threw load() exception 
java.lang.Error: Unresolved compilation problems: 
    Autowired cannot be resolved to a type 
    clientDAO cannot be resolved to a type 

を:

パッケージDAO。

import com.javatpoint.form.Client_Registration; 

public interface clientDAO { 
void insertData(Client_Registration patient); 
} 
+0

は、文脈があるclientDAO –

+0

私達にあなたのクラスを表示しますか? –

+0

コンポーネントスキャンにclientDAOのパッケージを含める必要があります –

答えて

0

この例外は、前述のタイプのBeanが作成されていない場合に発生します。 spring-servlet.xmlファイルにcontext:component-scanタグが追加されていることを確認してください。例:

ともあなたはダオ

0

に@Repository注釈を追加しているかどうかを確認するには、あなたのclientDAOクラスに@Repository追加されている願っています。 Springは読み込み時にそれを見つけることができません。 Beanの作成に使用した設定(xmlまたはjava)を確認してください。 共有完全なエラーログと適切なコードスニペット(ここではclientDAOと設定)を使用すると、エラー解決がより迅速になります。

0

あなたがそのようにDAOを注入する必要がありますコントローラパッケージとどのように私は、Beanを作成しないためのコンポーネントスキャン:

<bean id="dao" class="com.elgarnaoui.ma.dao.AgentDao"></bean> 
    <bean id="metier" class="com.elgarnaoui.ma.metier.MetierAgent"> 
     <property name="dao" ref="dao"></property> 
    </bean> 
関連する問題